Downward compatible extension to unions

John Hascall hascall at cs.iastate.edu
Wed Feb 14 03:15:36 AEST 1990


The more I think about the ANSI standard for union initialization, the
more I fail to understand it.  Was the following suggested, and if so,
what were the reasons for rejecting it?

   Make union initialization parallel to struct initialization except that
   only one element may be specified.

      struct FOO {                      union FOO {
          char  bar;                        char  bar;
          int   baz;                        int   baz;
          long  buz;                        long  buz;
      } examp = { 'C', 42, 61762 };     } examp = { , 42, };

   Note that this method would not break existing code using the
   "initialize the first element" rule (assumming trailing commas
   were optional).

   The real usefulness is when you have an array of unions which you
   may want to be initialize differently:

      union FOO  things[3] = { {,42,}, {'C',,}, {,,61762}, };

John Hascall  /  ISU Comp Ctr, Ames IA  /  hascall at atanasoff.cs.iastate.edu



More information about the Comp.lang.c mailing list