a better syntax for unions

utzoo!decvax!decwrl!sun!megatest!fortune!hpda!hplabs!hao!menlo70!sytek!zehntel!tektronix!tekecs!andrew utzoo!decvax!decwrl!sun!megatest!fortune!hpda!hplabs!hao!menlo70!sytek!zehntel!tektronix!tekecs!andrew
Fri Mar 25 12:20:20 AEST 1983


I also dislike the extra identifier required in references to members
of unions within structures, and I applaud Lee Iverson's approach to a
remedy, which closely resembles a useful feature of PL/I.  However, I
must point out some aspects in which this clashes with historical C.

The suggestion is that, for example, if the structure in question is:

	struct {
		int a;
		union {
			long l_b;
			float f_b;
			} u;
		} s;

that one be able to say "s.l_b" instead of "s.u.l_b".  Lee's solution
is to hack PCC so that member tags are searched for throughout the
structure, rather than only at the top level.

If you look back to earlier versions of C, which were more lax with
regard to matching tags with their structures, the construct "s.l_b"
above would mean to interpret the "s" structure as though it were in
fact a "u" union.  Thus, "s.l_b" on, say, a PDP-11 is the longword
occupying the first four bytes of the structure, rather than the
longword in the third through sixth bytes, as is intended.

Compilers that allow this also let you specify:

	struct foo {int _l;}
	0177400 -> _l = 0;

to clear the device register at location 0177400, rather than

	(struct foo *) 0177400 -> _l = 0;

I for one am willing to toss the historical behavior in favor of
the proposal.

  -- Andrew Klossner (decvax!tektronix!tekecs!andrew)



More information about the Comp.lang.c mailing list