Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Uninitialized global data (was Re: Global variables) Message-ID: <1988Mar25.173027.442@utzoo.uucp> Organization: U of Toronto Zoology References: <1744@phoenix.Princeton.EDU>, <978@mcgill-vision.UUCP> Date: Fri, 25 Mar 88 17:30:27 GMT > ... Imagine a machine on > which integer zero, floating zero, and null pointer have three > different bit patterns. Now, what is the following datum on program > startup? Presumably it's one of the three, or possibly all-bits-zero > regardless of whether this matches any of the above three.... Could > someone with access to the draft clear this up? > > union { int i; float f; char *cp; } funny; It gets initialized as if by "funny.i = 0". X3J11 says that initialization of unions is by their first member. (Please don't start another flame war over this, we've been through it several times before. X3J11 picked the minimum solution that made the initial state of static unions well-defined, a solution which had been used with some success by existing compilers. Nobody disputes that it is ugly and inflexible; if you wish to propose a better alternative, DON'T post it to the net -- implement it in your local C compiler, use it for a couple of years, and then submit it to X3J11 when the C standard comes up for revision. Implementation and successful use carries far more weight than words on paper.) -- "Noalias must go. This is | Henry Spencer @ U of Toronto Zoology non-negotiable." --DMR | {allegra,ihnp4,decvax,utai}!utzoo!henry