Path: utzoo!utgpu!attcan!uunet!husc6!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: Unions Summary: Also if you want to override strong typing Keywords: What can they be used for? Message-ID: <976@l.cc.purdue.edu> Date: 21 Oct 88 13:11:55 GMT References: <322@hrc.UUCP> <2699@hound.UUCP> Organization: Purdue University Statistics Department Lines: 28 In article <2699@hound.UUCP>, rkl1@hound.UUCP (K.LAUX) writes: > In article <322@hrc.UUCP>, dan@hrc.UUCP (Dan Troxel VP) writes: > > > > Except for the memory savings, what are Unions suited for? > > -- > > Dan Troxel VP of Computer Operations @ > > Handwriting Research Corporation - 2821 E. Camelback Road Suite 600 > > Phoenix, AZ 85016 WK 1-602-957-8870 HM 1-602-435-1240 > > UUCP : asuvax!hrc!dan Another use is so that the unnecessary restrictions of strong typing can be overcome. There are times when it is a good thing to use integer operations on floating point numbers (caution: machine dependent). An alternative would be to have a _use_ pseudooperation (distinct from cast), but even with it, I would want unions. It may also be desirable to have objects such as four bytes or two 16-bit words treated as a 32-bit word for certain purposes. I have treated two 32-bit words as a 64-bit word for shifting on a machine which could not shift 32-bit words. A programmer who has some understanding of the machine can come up with many of these. One complaint that I have about the C compilers I have used is that they do not support register unions. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (Internet, bitnet, UUCP)