malloced structure initilization

Carl Paukstis carlp at iscuva.ISCS.COM
Fri Feb 17 10:10:49 AEST 1989


In article <9649 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <1874 at dataio.Data-IO.COM> bright at dataio.Data-IO.COM (Walter Bright) writes:
>>Yah, and init_foo is guaranteed to be initialized to a 0 bit pattern,
>
>No, static storage is initialized to zero of the appropriate type,
>which need not be a 0 bit pattern in all cases.  The first few C
>implementations could use 0-bit fill for zeros of all types;
>other implementations may need the compiler to do something special
>to meet this requirement.

Now THIS is interesting!  As I remember, the original discussion was about
structures.  Does this mean that if I write:

  #include <stdio.h>

  static struct {
      float ward;
      int june;
      char wally;
      long beaver;
      double eddie;
      } mayfield;

  int main (int argc, char **argv)
  {
      printf("%f, %d, %c, %ld, %f\n",
            mayfield.ward, mayfield.june, mayfield.wally,
            mayfield.beaver, mayfield.eddie);
      return 0;
  }

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?  Presumably
that means that any pointers I mention in the structure are also set to
proper nil pointers of appropriate type?

Specifically, does the initialization of static variables to "zero of the
appropriate type" apply to members of static structures?
-- 
Carl Paukstis    +1 509 927 5600 x5321  |"The right to be heard does not
                                        | automatically include the right
UUCP:     carlp at iscuvc.ISCS.COM         | to be taken seriously."
          ...uunet!iscuva!carlp         |                  - H. H. Humphrey



More information about the Comp.lang.c mailing list