Unions

Tim Olson tim at crackle.amd.com
Mon Oct 24 06:56:42 AEST 1988


In article <981 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
| Here is a very simple example.  BTW, I have seen C sources which use precisely
| this construction.
| 
| union un {*int i; *float f;};
| 
| .....
| 
| register union un var1, var2;
| 
| Can anyone give me any conceivable reason why this union, whose size is
| exactly one register on the machines I have tried it on, is not put into
| an available register?  On one of the machines (Pyramid), local variables
| were normally put into registers, but the compiler would not put the union
| there.  I know this particular case can be done with casts, but other cases
| cannot.

The MetaWare C compiler for the Am29000 does precisely what you want --
it keeps all register-sized variables in registers, as long as their
address isn't taken in the function.  This includes unions, structs, and
even arrays.  Aggregates such as structs are also passed as parameters
to functions in registers.



	-- Tim Olson
	Advanced Micro Devices
	(tim at crackle.amd.com)



More information about the Comp.lang.c mailing list