Anyone care to share neat C tricks?

1 points by jackson_1 ↗ HN
Here's a C99 trick I learned recently, known as compound literals. Say you have a function that takes a struct as a parameter:

typedef struct {int x; int y;} Point;

void plot(Point p);

Normally, to call this function, you have to create a Point first:

Point p = {1, 2};

plot(p);

But, with compound literals, you can declare p anonymously:

plot((Point){1, 2});

Does anyone else have neat C tricks to share?

0 comments

[ 5.0 ms ] story [ 7.2 ms ] thread

No comments yet.