malloced structure initilization

Jim Patterson jimp at cognos.uucp
Wed Feb 15 05:31:56 AEST 1989


In article <1874 at dataio.Data-IO.COM> bright at dataio.Data-IO.COM (Walter Bright) writes:
>In article <8894 at alice.UUCP< ark at alice.UUCP (Andrew Koenig) writes:
><In article <202 at sabin.UUCP<, bjm at sabin.UUCP (Brendan J. McMahon) writes:
><	static struct foo init_foo;
><init_foo is guaranteed to be initialized because it's static.
>Yah, and init_foo is guaranteed to be initialized to a 0 bit pattern,

Not so, according to the pANS C. See section 3.5.7:

  "If an object that has static storage duration is not
  initialized explicitly, it is initialized implicitly as if
  every member that has arithmetic type were assigned 0 and
  every member that has pointer type were assigned the null
  pointer constant"

As far as I know, on every known architecture supporting C the effect
is exactly the same anyways.

(Somebody, please correct me IF YOU KNOW OF A COUNTER EXAMPLE. I've
seen too many people say that it's not guaranteed by pANS C, which I
know, but I have not yet seen the name of a single machine or system
with a C compiler for which it isn't true).
-- 
Jim Patterson                              Cognos Incorporated
UUCP:decvax!utzoo!dciem!nrcaer!cognos!jimp P.O. BOX 9707    
PHONE:(613)738-1440                        3755 Riverside Drive
                                           Ottawa, Ont  K1G 3Z4



More information about the Comp.lang.c mailing list