Reputation: 49393
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
— A structure type describes a sequentially allocated nonempty set of member objects (and, in certain circumstances, an incomplete array), each of which has an optionally specified name and possibly distinct type.
So, not surprisingly when attempting to compile something like:
struct foo
{
};
In MS VS, there's some error thrown:
error C2016: C requires that a struct or union has at least one member
However, when compiling the same code with gcc -Wall -Werror
there are no errors seen. So...
gcc
to make it catch this issue? Upvotes: 5
Views: 596
Reputation: 145829
Yes, a structure type with no member is not valid in C.
-Werror -pedantic
with gcc
will stop the translation.
Upvotes: 7