Since c99
compound literals can be used to e.g. initialize pointers:
int *p = (int []) {1, 2, 3, 4};
while this is usually used for struct
s it can be used to initialize anonymous arrays as well (see example). But if I understood this correctly initializing a scalar pointer like this:
int *p = &(int) {4};
is also valid. What I find confusing is the statement on the gcc
site that “Compound literals for scalar types and union types are also allowed, but then the compound literal is equivalent to a cast.” Do they simply mean that using the address-of operator &
in front of an anonymous scalar is a form of casting?