Uninitialized global data (was Re: Global variables)

Henry Spencer henry at utzoo.uucp
Sat Mar 26 03:30:27 AEST 1988


> ... 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



More information about the Comp.lang.c mailing list