Discussion

Anyone care to share neat C tricks?

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?

1 points jackson_1 10 years ago 0 comments

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton