In C++, unlike in C, an empty array T name[] is illegal,
the type declared is "array of unknown bound of T", which is a kind of incomplete type.
However, it is legal when
used in a declaration with an aggregate initializer
like T name[] = {val1, val2, ...}, where the array is allocated with the number of elements in the initializer list.
What is the expected behaviour when the aggregate initializer is empty? T name[] = {}
I have tested g++ (version 4.8.4) and clang (version 3.4), neither of which give any error or warning, and seem to allocate 1 element. Is this the defined behaviour? Documentation?
int a[] = {};
int b[] = {};
Results in:
a[0] -> 0x7ffc3de28dd8
a[1] -> 0x7ffc3de28ddc
b[0] -> 0x7ffc3de28ddc
b[1] -> 0x7ffc3de28de0
sizeof(a)/sizeof(a[0])