I noticed that when compiled with GCC 4.6 sizeof(Foo) is 0 and sizeof(Bar) is 1. For some reason adding an empty array into an empty structure made its size 0. I thought that the sizes of both structures must be the same. What is going on here?
struct Foo
{
char x[];
};
struct Bar {};
Neither
structdeclaration is allowed by the C standard. 6.7.2.1 (8) in n1570:And paragraph 18 in the same section:
(emphasis mine)
Flexible array members are not allowed in C++, so the code is not valid C++ either.
As it is not valid code, the values reported by
sizeoffor these are meaningless.