register unions

Tainter tainter at ihlpg.ATT.COM
Sat Feb 20 10:43:31 AEST 1988


In article <6831 at ccv.bbn.COM>, kgregory at bbn.COM (Keith D. Gregory) writes:
> In article <1229 at eneevax.UUCP> noise at eneevax.umd.edu.UUCP 
> (Johnson Noise) writes:
> > [ A STATEMENT THAT REGISTERIZING A SUBSET OF UNIONS WOULD BE USEFUL ]

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

This is a specious argument.  One cannot give examples of problems when the
compiler is free to pick and choose which of your register declarations to
ignore and which to implement.

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

I don't see anything prohibiting this.  To access a field you do byte swaps
or copy to another register and mask etc, depending on what's available in your
instruction set.  This might be less expensive than offset calculation and
memory referencing.  On something without byte addressability it might implement
it with register loads, shifts and masks anyway.  In which case a register to
register copy is bound to be quicker than fecthing from memory.

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

What problems does this have?  field one obviously presents no problems.
field2 is very easy to handle with byte swaps and byte instructions
(assuming the machine has such).  Now, if you intend to pull bytes out of
that int it isn't required that the compiler provide such capability anyway.

> -kdg

--j.a.tainter



More information about the Comp.lang.c mailing list