C++ Structures Unions

Just starting out? Need help? Post your questions and find answers here.
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

C++ Structures Unions

Post by LiK137 »

Hi,

I need a help, explanation regarding C structs.
struct name and elements for testing purpose, not real just to understand for proper conversion.
Especially this " __C89_NAMELESS union" part not clear to interpret structures
Thanks in advance.

Code: Select all

typedef struct _ABCD {
  ABC1 E;
  __C89_NAMELESS union {                          ; - this line is unclear (__C89_NAMELESS union)
    struct {
      ULONG F;
    } E1;
  } G;
} ABCD, *PABCD;    - this line is clear and understood

typedef struct _ZXCV {
  _ZXCVB              ZXCVB;
  __C89_NAMELESS union {
    struct {
      ULONGLONG           A;
      ULONG               B;
    } ZZZZ;
    GUID                  ID;
    struct {
      BOOL                CBool;
      WCHAR               DBuffer[1];
    } XXXX;
    GUID                  PID;
    _ABCD               ABCD ;
  } DUMMYUNIONNAME;                        - And this line is unclear (DUMMYUNIONNAME)
} ZXCV, *PZXCV;

User avatar
spikey
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: C++ Structures Unions

Post by spikey »

At a guess the compiler orginally used expects a union to be named; generates a syntax error if it doesn't and the __C89_NAMELESS flag/macro overrides this behaviour so an anonymous union can be implemented. See https://en.cppreference.com/w/cpp/langu ... ous_unions

You can ignore it, and the dummy union names too, for the purposes of converting to PB as all unions are anonymous.
Post Reply