Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!purdue!i.cc.purdue.edu!k.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: Register unions Summary: Look carefully. Message-ID: <983@l.cc.purdue.edu> Date: 24 Oct 88 12:40:32 GMT References: <322@hrc.UUCP> <2699@hound.UUCP> <976@l.cc.purdue.edu> <8741@smoke.BRL.MIL> Organization: Purdue University Statistics Department Lines: 43 In article <8741@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn ) writes: > >> In article <976@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: > >> >One complaint that I have about the C compilers I have used is that they > >> >do not support register unions. > > The point is, on many architectures not all basic data types could actually > share a register. Your original example was of an integer and a floating > type sharing a register, which doesn't work on any machines I'm aware of. > And obviously a union of large types would not fit into a register. On the VAX and PYRAMID, single precision floating point and integer both take up exactly one register. But that is not the example I gave. I have used the other in a situation where it obviously saved time. I put down the address of an integer and the address of a floating point number. There are very few machines where these take up different amounts of space. Of course, if something cannot fit into the registers available, it cannot be made register. But this is no reason to ignore the programmer. And there is even less reason not to put a union into a register because it is a union when any other pointer would have been put into a register. > Simply permitting "register" to be crammed on the front of "union" would > do no good; the hardware would have to actually support the usage for > this to be worthwhile. If the hardware DOES support this, its C > implementation is allowed to use an actual register (so long as the > address is not taken). Good optimizing C compilers ignore the "register" > specifiers and do their own register allocation anyway. I have not even seen a fair optimizing C compiler. In a university environ- ment, one has little say in this. I can say that the 4.xBSD compiler does not allow certain registers to be used by the programmer, even if they are available. It does not allow the use of symbolic registers in asm line. There are too many other things it does not allow, and the simple idea of register unions is one of them. BTW, in the book, whose title and authors slip my mind, on the use of lex and yacc in constructing a C compiler, the authors use register unions. I have seen register unions used in widely published C sources. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (Internet, bitnet, UUCP)