Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 (Tek) 9/26/83; site orca.UUCP Path: utzoo!watmath!clyde!floyd!harpo!seismo!hao!hplabs!tektronix!orca!andrew From: andrew@orca.UUCP (Andrew Klossner) Newsgroups: net.lang.c Subject: Re: comparing structures: problems with unions Message-ID: <735@orca.UUCP> Date: Sun, 25-Mar-84 23:42:11 EST Article-I.D.: orca.735 Posted: Sun Mar 25 23:42:11 1984 Date-Received: Wed, 28-Mar-84 01:12:12 EST References: <253@opus.UUCP> <365@denelcor.UUCP> Organization: Tektronix, Wilsonville OR Lines: 22 "Another solution would be to clear the unused parts of the union wherever a store is done. In many cases (admittedly not all) this would be very cheap." In some cases it can't be done at all: struct { union {char c; double d;} u; } structure; fill_char(pc) char *pc; {*pc = ~0;} main() { ... fill_char(&(structure.u.c)); ... } The code generated for "fill_char" has no way of knowing that the character to which it's been given a pointer is a member of a larger union, the excess of which must be cleared. -- Andrew Klossner (decvax!tektronix!orca!andrew) [UUCP] (orca!andrew.tektronix@rand-relay) [ARPA]