Reputation: 20746
Where can we use anonymous structs and unions?
struct
{
int bar;
}; // anonymous struct
union
{
int bar;
}; // anonymous union
I think that we can do it in the following standards:
unions - C++98, C++03, C++11, C11
structs - C11
Am i right or not
Upvotes: 7
Views: 2577
Reputation: 2720
The statement about C is correct: the standardization of anonymous structs and unions is pretty new (C11) cfr. GCC man.
Note that your preferred compiler could enable those features as extensions to the current supported standard (e.g. GNU C99 extensions).
Then, checking old specs, it seems that anonymous unions are supported in C++ since 1998.
It is common knowledge that anonymous structs are forbidden in C++ and I did not find any amendment. As of Visual studio 2012, C++ is confirmed not supporting this feature.
Upvotes: 5