If you’re using older C++ variants (pre-C++0x), then this is not allowed. The “anonymous array” you refer to is actually an initializer list. Now that C++11 is out, this can be done with the built-in initializer_list
type. You theoretically can also use it as a C-style initializer list by using extern C
, if your compiler parses them as C99 or later.
For example:
int main()
{
const int* p;
p = (const int[]){1, 2, 3};
}