C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Anonymous Union
                                             Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
     In C++, an anonymous union is a union without a tag or
     declarators; it declares an unnamed object. An anonymous union
     cannot have member functions or private or protected members.
 
     A global anonymous union must be static. A local anonymous union
     must be either static or automatic, not external.
 
     In C, an anonymous union can have a tag; it cannot have
     declarators.
 
     The name of each member must be unique within the scope where the
     union is declared. You can directly access the members of an
     anonymous union as follows:
 
          static union       // Global anonymous unions must be static
          {
             int i;
             float f;
             union
             {
                 char c;
                 unsigned char uc;
             };
          };
 
          void my_func()
          {
              i = 1;
              f = 3.14;
              c = 'c';
              uc = 'u';
          };
                                    -♦-