Path: utzoo!mnetor!uunet!oddjob!gargoyle!ihnp4!ihlpg!tainter From: tainter@ihlpg.ATT.COM (Tainter) Newsgroups: comp.lang.c Subject: Re: register unions Message-ID: <4879@ihlpg.ATT.COM> Date: 20 Feb 88 00:43:31 GMT References: <1229@eneevax.UUCP> <6831@ccv.bbn.COM> Distribution: comp.lang.c Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 35 Keywords: registers unions structures In article <6831@ccv.bbn.COM>, kgregory@bbn.COM (Keith D. Gregory) writes: > In article <1229@eneevax.UUCP> noise@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