Standard for union initialization?

Norman Diamond ndiamond at watdaisy.UUCP
Tue Jan 8 03:50:32 AEST 1985


> > why not use a more general scheme like
> > 
> > 	union {
> > 	    <type1> foo;
> > 	    <type2> bar;
> > 	    <type3> mumble;
> > 	} baz.mumble = <type3 initializer>;
> 
> But "baz.mumble" is not what you want the union to be called.
> This addition would certainly make for a messier language
> syntax definition.

Why not fix the syntax of that scheme and use its semantics:

union {
    <type1> foo;
    <type2> bar;
    <type3> mumble;
} baz = (type3) <initializer>;

Suppose the same type is duplicated in the union, e.g. suppose type3 is
the same as type1 and the compiler doesn't know whether to initialize
foo or mumble?  Let the compiler choose whichever valid one it wishes;
the result would be equivalent.

This would not make the language any messier; it is better than many
other examples of casts.  And it would be useful, and it would not break
existing programs.

-- Norman Diamond

UUCP:  {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy at waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet at csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."



More information about the Comp.lang.c mailing list