Unions

Herman Rubin cik at l.cc.purdue.edu
Fri Oct 21 23:11:55 AEST 1988


In article <2699 at hound.UUCP>, rkl1 at hound.UUCP (K.LAUX) writes:
> In article <322 at hrc.UUCP>, dan at 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 at l.cc.purdue.edu (Internet, bitnet, UUCP)



More information about the Comp.lang.c mailing list