C++ 0x draft
9.5.6 Anonymous unions declared in a named namespace or in the global namespace shall be declared static.
Why is this?
Suppose anonymous unions were not required to be declared static, and the compiler encounters these two translation-units (after preprocessing):
File1:
union {
int a;
char b;
};
// Further contents referring to a and b
File2:
union {
int a;
char b;
};
// Further (different) contents referring to a and b
Are those two unions one an the same object, or are they supposed to be different objects?
I think that, in order to avoid unanswerable questions like this, it has been decided that namespace-scope anonymous unions have to be declared static.
My guess is that if it were allowed to define the union in a non static way it may violate the ODR (one definition rule)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With