Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!sdd.hp.com!wuarchive!psuvax1!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: time(0L) - history of a misconception Message-ID: <16294@smoke.brl.mil> Date: 29 May 91 07:48:14 GMT References: <1991May25.002706.27552@kithrup.COM> <1991May25.221530.16119@zoo.toronto.edu> <1991May28.175246.2160@holos0.uucp> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 33 In article <1991May28.175246.2160@holos0.uucp> lbr@holos0.uucp (Len Reed) writes: >Okay, what about static and global pointers not explicitly initialized? Before any reference to them, they must somehow be initialized by the implementation to null pointers of the appropriate types. >Older Unices (not sure about the newest) depended upon the kernel's >zeroing out of the BSS to hit global and static data with zeros. On the PDP-11 and VAX, that was a valid implementation technique. Note that it also default-initialized floating-point variables to zero values of the correct types. Not every environment has such pleasant properties; in other situations the compiler may have to emit explicit initialization code (e.g. .ADCON 0xFFFF directives). >Finally, what if I malloc a my_struct and memset it to zeros? That properly initializes the integral (sub)members but not necessarily other basic types. >But I don't do it now, and I know lots of folks who don't. Why not? You should certainly properly set the value of a variable before trying to use it. I even write explicit initializers for static objects when the initial value matters, as an indication that (a) I have thought about the initial contents and (b) the particular initial value is necessary for correct operation of the code. By the way, you may find that your code adapts better, for example to parallelization, if you initialize using assignment instead of counting on the static initializer.