register unions

Keith D. Gregory kgregory at bbn.COM
Sun Feb 14 04:44:03 AEST 1988


In article <1229 at eneevax.UUCP> noise at eneevax.umd.edu.UUCP 
(Johnson Noise) writes:
> [code examples deleted]
>
>which would effectively allow full use of cpu registers.  Note the
>similarity to 68k assembly.  Unfortunately, all the compilers I have
>tried (including pcc) will not allocate unions in registers.  My initial
>suspicion is that most compilers simply do not allow anything other than
>basic types to be allocated in registers.  I realize that combining
>pointers and non-pointers in 68k systems is not possible, but I don't
>intend to do that.  I don't see any immediate problems in allowing
>such a declaration (with checks on 68k's).

I think that the answer becomes apparent with some more code examples :-)

struct mystruct {
	char	field1, field2, field3, field4;
	};

union myunion {
	int	field1;
	char	field2[2];
	};


The first example of course, would fail on the 68000 right away - you
can't arbitrarily split a register into 4 bytes.  The second is simply
more of the same, and the key point is that structures and unions are
manipulated using pointer arithmetic (to access the fields therein), and
pointers to registers can not exist.

-kdg



More information about the Comp.lang.c mailing list