On Thu, Nov 13, 2008 at 12:23:16AM +0100, nadult wrote:
> Hello, i have some problems with empty (almost) structures containing
> zero-sized arrays:
>
> struct Zero { int value[0]; };
> int main() {
> std::cout << "sizeof(Zero)==" << sizeof(Zero) << '\n';
> return 0;
> }
>
> The output i get for every g++ i compile it on is:
> sizeof(Zero)==0
Zero-sized arrays aren't allowed in standard C++.
However, I think that this result is a bug, because g++ will normally
ensure the size is at least one, so that each object in an array
(or a struct/class with multiple instances of the same object) have
distinct addresses.
> Is this a bug, or maybe zero-sized arrays are gcc extension not fully
> supported in g++?
Both, I think.