Initialization of unions

Dick Grune dick at tjalk.UUCP
Mon Jun 3 20:30:45 AEST 1985


Since the whole matter of initializing unions has been rekindled, I venture
to resubmit my letter of almost a year ago.

I saw a suggestion for the initialization of unions in net.lang.c
a few months ago that I found very sensible, readable and hygienic:

        union   {
                int i;
                float x;
                char *str;
        } ixstr = { , 3.14, };

if you want it to start off as a float, etc.

Note that:
1. it is (almost) isomorphous to a struct initialization,
2. it also works nicely for arrays of unions.

					Dick Grune
					Vrije Universiteit
					de Boelelaan 1081
					1081 HV  Amsterdam
					the Netherlands



More information about the Comp.lang.c mailing list