Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!uunet!kithrup!sef From: sef@kithrup.COM (Sean Eric Fagan) Newsgroups: comp.lang.c Subject: Re: time(0L) - history of a misconception (was Re: SCO password generator) Message-ID: <1991May29.002529.22232@kithrup.COM> Date: 29 May 91 00:25:29 GMT References: <1991May25.002706.27552@kithrup.COM> <1991May25.221530.16119@zoo.toronto.edu> <1991May28.175246.2160@holos0.uucp> Organization: Kithrup Enterprises, Ltd. Lines: 47 In article <1991May28.175246.2160@holos0.uucp> lbr@holos0.uucp (Len Reed) writes: >Okay, what about static and global pointers not explicitly initialized? They are guaranteed to hold the same value as if they had been explicitly initialized to 0. >static char *s_ptr; /* Is s_ptr NULL or all-zeros? */ This is equivalent to static char *s_ptr = 0; >What about pointers inside structs? E.g., > >struct my_struct { > int *pointer; > int abc; >} instance; I believe that this is equivalent to struct my_struct { int *pointer; int abc; } instance = { 0 }; That is, the first element is set to 0. Which will get treated as NULL for whatever machine it's compiled for. (For the vast majority of cases, no problem, for those that are, they may have several "bss" segments, or some initialization code that set things up appropriately.) >Finally, what if I malloc a my_struct and memset it to zeros? No way this >can work: You're right, there is no way it can work. Which means you can't use calloc() for some things that used to be done. What you have to do is, if you want to be portable, go through and initialize everything yourself, instead of using a memory-setting routine to do it for you. >But I don't do it now, and I know lots of folks who don't. And I know lots of folks who make lots of assumptions about word sizes, which causes even more problems, or about a writable (or, worse, readable) location 0. Doesn't mean it's good practice. -- Sean Eric Fagan | "I made the universe, but please don't blame me for it; sef@kithrup.COM | I had a bellyache at the time." -----------------+ -- The Turtle (Stephen King, _It_) Any opinions expressed are my own, and generally unpopular with others.