Path: utzoo!utgpu!attcan!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.lang.c Subject: Re: Unions Keywords: What can they be used for? Message-ID: <1559@solo8.cs.vu.nl> Date: 21 Oct 88 16:32:19 GMT References: <322@hrc.UUCP> <1532@valhalla.ee.rochester.edu> Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Informatica, Amsterdam Lines: 17 \In article <322@hrc.UUCP>, dan@hrc.UUCP (Dan Troxel VP) writes: \ \ Except for the memory savings, what are Unions suited for? Beside reasons mentioned so-far, there's alignment: union _u { int i; char buf[17]; } u; This construct will let you safely read an integer starting at &u.buf[0], i.e. no bus error will occur. K&R: a union can be thought of as a struct, all whose fields begin at offset 0. -- Hippic sport: |Maarten Litmaath @ Free U Amsterdam: a contradiction in terms.|maart@cs.vu.nl, mcvax!botter!maart