Path: utzoo!utgpu!water!watmath!clyde!burl!codas!ki4pv!tanner From: tanner@ki4pv.uucp (Dr. T. Andrews) Newsgroups: comp.lang.c Subject: Re: register unions Summary: yuppers, and here's really why Keywords: registers unions structures Message-ID: <7450@ki4pv.uucp> Date: 14 Feb 88 15:50:08 GMT References: <1229@eneevax.UUCP> <6831@ccv.bbn.COM> Distribution: comp.lang.c Organization: CompuData, DeLand Lines: 34 In article <6831@ccv.bbn.COM>, kgregory@bbn.COM (Keith D. Gregory) writes: ) In article <1229@eneevax.UUCP> noise@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