malloced structure initilization

Guy Harris guy at auspex.UUCP
Sat Feb 18 20:07:05 AEST 1989


 >Does this mean that if I write:
 >
 >  #include <stdio.h>
 >
 >  static struct {
 >      float ward;
 >      int june;
 >      char wally;
 >      long beaver;
 >      double eddie;
 >      } mayfield;
 >
 >I'm GUARANTEED (at least by the ANSI standard) to get (something like):
 >
 >    0.0, 0, <NUL>, 0, 0.0
 >
 >even on "unusual" architectures where zero-bit-pattern != 0?

Yes (if <NUL> means '\0').

>Presumably that means that any pointers I mention in the structure are
>also set to proper nil pointers of appropriate type?

Yes.

>Specifically, does the initialization of static variables to "zero of the
>appropriate type" apply to members of static structures?

Yes.  From the May 13, 1988 dpANS:

	3.5.7 Initialization

	...

	  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 a null pointer constant.



More information about the Comp.lang.c mailing list