This answer of mine generated some comments claiming that the following construct is not legal C/C++:
void f (int* a) ;
f ((int[]){1,2,3,4,0}) ;
(see this ideone link for a full program). But we weren’t able to resolve the issue. Can anybody shed any light on this? What do the various standards have to say?
It’s valid C99 as far as I can tell – that’s passing a compound literal.
The C99 standard has this as an example (§6.5.2.5/9):
Note that the
(int [])thing is not a cast here.This is not a valid C++ construct though, compound literals are not part of the C++ standard (C++11 included). Some compilers allow it as an extension. (GCC does, pass
-Wall -pedanticto get a diagnostics about it. IBM xlC allows it as an extension too.)