register unions

Doug Gwyn gwyn at brl-smoke.ARPA
Sat Feb 13 17:44:01 AEST 1988


I think it's a valid notion.  Notice that the compiler would have
to determine whether or not to assign a genuine register variable
for the union based on what the member types are (they must all
be compatible with the register).  Also, only non-scratch
registers could be allocated, so for example on a 68000 register
D0, used as a scratch register in the generated code, would not
be assigned to such a union.  Which registers you got would of
course depend on the register allocation strategy of the compiler.
(You may get stack storage instead, if it runs out of registers.)
You may need to add a check for & being applied to such a union,
which should be illegal by normal C rules but may not be checked
for in a compiler that didn't think unions would ever be in real
registers.

On the other hand, I don't think this is nearly as useful as
you seem to think it would be.  Why would you want to twiddle
specific registers when not having to be concerned with such
matters is the whole point of using a higher-level language?



More information about the Comp.lang.c mailing list