a better syntax for unions

utzoo!decvax!harpo!eagle!mhtsa!alice!npoiv!npois!houxm!5941ux!machaids!hocda!spanky!ka utzoo!decvax!harpo!eagle!mhtsa!alice!npoiv!npois!houxm!5941ux!machaids!hocda!spanky!ka
Tue Mar 29 14:37:39 AEST 1983


I have never liked the extra level introduced by the union concept.
Basicly, the union declaration does two things:  it overlays the
specified variables, and it places the variables in a structure.
Why not an overlay declaration which overlays variables without
putting them in a structure?  If the programmer wants the elements
of the overlay to be in a structure, he/she can declare the struct-
ure explicitly.  For example,

	union u {
		int ivar;
		float fvar;
	} un;

could be written as

	struct u {
		overlay {
			int ivar;
			float fvar;
		}
	} un;

The union construct is simpler here because it avoids an extra level of
nesting, but the second construct may be clearer because two unrelated
operations, overlaying variables and placing variables into a structure,
are not combined into one construct.  More importantly, in most cases
overlayed variables don't belong in a structure.  The C union construct
forces you to put them in a structure anyway, obscuring your program.
				Kenneth Almqust



More information about the Comp.lang.c mailing list