Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!pacbell!att!whuts!homxb!hound!rkl1 From: rkl1@hound.UUCP (K.LAUX) Newsgroups: comp.lang.c Subject: Re: Unions Keywords: What can they be used for? Message-ID: <2699@hound.UUCP> Date: 20 Oct 88 16:55:56 GMT References: <322@hrc.UUCP> Organization: AT&T Bell Laboratories, Holmdel Lines: 20 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 The purpose of Unions is so that several different data types can be stored in a common memory location (but you've already said that). Of course you can get into trouble if you have and int and a float in a union and store a floating value there, then pull it out as an int :-). One use of unions is to have different pointer types declared in one and then having the union as part of a structure. Then you could use malloc and cast the pointer returned to various types as needed. This would allow for your code to manipulate the structure with multiple types of pointers in it. --rkl