register unions

Dr. T. Andrews tanner at ki4pv.uucp
Mon Feb 15 01:50:08 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 
) > [code examples deleted]
) I think that the answer becomes apparent with some more code
) examples :-)
) [code examples where a register is not appropriate on machine 'X' ]

You miss the point.  In certain cases, which cases will vary from
machine to machine, it is desirable to put a union in a register.
For instance, to preserve registers or (more likely) to walk through
more than one kind of structure, you might put a union of several
pointers in a register.

The compiler should, when appropriate, put these unions into
registers.  Oh, do I need the standard code examples?

union _ptrs { struct _foo *foo_ptr; struct _bar *bar_ptr; }
	/* .. now, within a function  */
	register union _ptrs my_ptr;
	if (dealing_with_foo)
		my_ptr.foo_ptr = &foo_struct;
	else
		my_ptr.bar_ptr = &bar_struct;

A "good" compiler should know that it can put my_ptr into a register
(unless using some architecture where pointers don't fit into
registers; names omitted here to protect intel).

I suspect that few compilers are actually smart enough to put my_ptr
into a register, however.  The obligatory chorus of compiler vendors
bragging on \fItheir\fP compilers goes in messages immediately
following.
-- 
{allegra clyde!codas decvax!ucf-cs ihnp4!codas killer}!ki4pv!tanner



More information about the Comp.lang.c mailing list