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.
This “bug” has existed in the standard since C89:
I haven’t actually looked through the standard to check this parse, I’ve taken gcc’s word for it, but informally the need for a matching
:to each?trumps both operator precedence and argument list syntax to make the first statement work. No such luck with the second.