register unions

Johnson Noise noise at eneevax.UUCP
Sat Feb 13 10:43:38 AEST 1988


	While testing the availaility of register variables on several
machines and compilers, I thought of this possibility:

	typedef union
	{
		char b;
		short w;
		long l;
	} dreg;

	typedef union
	{
		char *b;
		short *w;
		long *l;
	} areg;

	register dreg d0, d1, d2;
	register areg a0, a1;

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).
	Has anyone else considered this possibility? Is there a compiler
which allows this?  If it were possible, one could almost write exact
assembly in C.  It probably is not neccessary for the most part, but
it would further reduce the neccessity of assembly (not to mention tearing
up benchmarks :-). Comments, flames?
	If there aren't any problems, I would like to incorporate these
and other concepts into my copy of gcc.



More information about the Comp.lang.c mailing list