Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: union initialization Message-ID: <6483@mimsy.UUCP> Date: Tue, 28-Apr-87 02:44:49 EDT Article-I.D.: mimsy.6483 Posted: Tue Apr 28 02:44:49 1987 Date-Received: Wed, 29-Apr-87 05:00:21 EDT References: <3290@burdvax.PRC.Unisys.COM> <1722@plus5.UUCP> <455@haddock.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 64 In article <455@haddock.UUCP> karl@haddock.UUCP (Karl Heuer) writes: >ANSI proposes that unions be initializable, but only to their first member. >The sudden introduction of a distinguished member of a (previously unordered) >union bothers me a bit; I feel they're attacking the symptom instead of the >problem. To refresh memories (in some cases) or provide background (in others), the problem, or symptom, is this: Uninitialised variables that have static allocation (that is, globals and local static variables) are, in C, defined as though they were initialised to `zero'. That is, given foo.c: % cat foo.c int i; double d; char *cp; % code compiled with foo.c this must perform equivalently to code compiled with this: int i = 0; double d = (double) 0; /* casts included for clarity */ char *cp = (char *) 0; /* (C does not require them) */ In most existing systems, this is trivial because 0 and 0.0 and (char *)0 are all all-zero bit patterns, and operating systems or runtime startups need know only how many bits of zeros are required (the infamous `bss' space). There are machines, though, in which not all of these are all zero bit patterns; a Lisp machine with tagged pointers take the source to mean four_byte_object "i" 0, 0, 0, 0 # integer 0 eight_byte_object "d" 0, 0, 0, 0, 0, 0, 0, 0 # 0 exponent five_byte_object "cp" 0, 0, 0, 0, 3 # 3 = nil tag in which case `i' and `d' might be put in bss space, but cp would be in initialised data space. This leaves us with the problem of unions: union { int i; double d; char *cp; } u; What can our tagged-pointer Lisp machine do? It can make u.i 0, or it can make u.d 0.0, or it can make u.cp NULL, but it cannot possibly do all three, for the last two conflict. The dpANS assigns meaning to this case by using a `first member' rule: On our Lisp machine, we set u.i = 0, and the other members are undefined. Another potential answer is to say that *none* of the members are defined. Even if we were to introduce aggregate constants, including union constants, we would still have to define uninitialised global or static union values: Which member or members are in fact initialised? You may not like the answer in the dpANS, but there must be an answer. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chrisredibedef hneu-