In C99, we have compound literals, and they can be passed to functions as in:
f((int[2]){ 1, 2 });
However, if f
is not a function but rather a function-like macro, gcc barfs on this due to the preprocessor parsing it not as one argument but as two arguments, "(int[2]){ 1
" and "2 }
".
Is this a bug in gcc or in the C standard? If it's the latter, that pretty much rules out all transparent use of function-like macros, which seems like a huge defect...
Edit: As an example, one would expect the following to be a conforming program fragment:
fgetc((FILE *[2]){ f1, f2 }[i]);
But since fgetc
could be implemented as a macro (albeit being required to protect its argument and not evaluate it more than once), this code would actually be incorrect. That seems surprising to me.
-std=c99
option acceptsMACRO_FX( ( (int[2]){1, 2} ) )
to group the expression in your example into one argument. – Clerestorydo
/while
trick, custom blocks based onfor
, or macros that eat types/operators (at least one of which -offsetof
- is in the standard). – Whitebeam