FrozenHeart
FrozenHeart

Reputation: 20746

Which standards allow anonymous structs and unions in C and C++?

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:

Am i right or not

Upvotes: 7

Views: 2577

Answers (1)

ziu
ziu

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

Related Questions