I have a question about empty structures in C. As far as I can tell from reading the standards, it seems that they are not allowed:
6.2.5-20
- The type of structure describes a sequentially allocated non-empty set of member objects (and, in some cases, an incomplete array), each of which has an optional specified name and, possibly, a separate type.
So, no wonder when you try to compile something like:
struct foo { };
There is some error in MS VS:
bug C2016: C requires a structure or union to have at least one element
However, when compiling the same code with gcc -Wall -Werror , no errors are visible. So that...
- Am I reading the specification correctly that this is not allowed in C? (and more surprisingly, Microsoft got it right ?!)
- Is there an option that can be passed to
gcc to catch this problem?
source share