Here is a struct
that I have:
typedef struct
{
float r, g, b;
} color_t;
I'd like to pass a compound literal of this struct
to a function as argument, like this:
void printcolor(color_t c)
{
printf("color is : %f %f %f\n", c.r, c.g, c.b);
}
printcolor({1.0f, 0.6f, 0.8f});
However, this gives me an error:
error: expected expression before '{' token
printcolor((color_t) {1.0f, 0.6f, 0.8f});
Don't be fooled by the cast-like syntax. It's not a cast, it's still a compound literal. – Weinshienk