Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!henry
From: henry@utzoo.UUCP (Henry Spencer)
Newsgroups: net.lang.c
Subject: Re: Must a NULL pointer be a 0 bit pattern?
Message-ID: <4512@utzoo.UUCP>
Date: Mon, 22-Oct-84 13:59:26 EDT
Article-I.D.: utzoo.4512
Posted: Mon Oct 22 13:59:26 1984
Date-Received: Mon, 22-Oct-84 13:59:26 EDT
References: <6542@mordor.UUCP> <529@wjh12.UUCP>, <504@plus5.UUCP>
Organization: U of Toronto Zoology
Lines: 24
Keywords: union initialization

> It would be much more useful to be able to (explicitly) initialize a union
> to *any* legal value.  I don't see why this is either bad or hard.  K&R
> states in 6.8 (page 139) that "It is the responsibility of the programmer
> to keep track of what type is currently stored in a union;...".

The problem is, *which* member of the union are you initializing?  If your
union has int and double members, and you initialize it to 0, which member
does this initialize?  Remember that C converts int to double as necessary.
Suppressing the conversion for this case only is an awkward special case,
and creates other problems.

Nobody contends that the "first member" rule is a particularly useful way
of initializing unions.  It is there because (a) "doing it right" isn't
easy and there is little experience with the problems created, but (b) it
really is necessary to make initialization of unions meaningful, if only
so you can answer questions like "what does initialization to 0 mean?".
The "first member" rule is solely a matter of needing to do something,
not having any clear indication that there is any "best" way, and wanting
to avoid dangerous complexity.  The "first member" rule has the virtue
that there *is* implementation experience with it, so its effects are
understood to some extent.  Not true of most alternatives.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry