On 10/19/16 07:51 AM, Rick C. Hodgin wrote:
> I'm using Visual Studio 2010 for a particular application, and its VC++
> compiler has the requirement that this code declared with a static
> global anonymous union:
>
> // Fails:
> union {
> int a1;
> HWND w1;
> };
>
> // Succeeds:
> static union {
> int a2;
> HWND w2;
> };
>
> Is it a C++ requirement that global anonymous unions be declared static,
> or just Microsoft's VC++ compiler requirement?
C++. See section 9.5 pp5&6 of the C++11 standard.
> If it's a C++ requirement,
> why is it a requirement? What would be the difference between a global
> anonymous union and a static global anonymous union? How would the
> compiler see them as different?
As a guess I'd say it has to be static because the members are in the
scope in which the union is declared.
--
Ian