Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!medar!jseymour From: jseymour@medar.com (James Seymour) Newsgroups: comp.lang.c Subject: Re: Just above and below main() Message-ID: <111@hdwr1.medar.com> Date: 13 Apr 91 14:07:31 GMT References: <1243@nanometrics.UUCP> <18473@crdgw1.crd.ge.com> Organization: Medar, Inc. Farmington Hills, MI Lines: 55 In article <18473@crdgw1.crd.ge.com> volpe@camelback.crd.ge.com (Christopher R Volpe) writes: |In article , |wolfram@cip-s08.informatik.rwth-aachen.de (Wolfram Roesler) writes: ||>stealth@nanometrics.portal.UUCP (Steve Sabram) writes: ||> ||>>_________________________ ||> ||>>int outside; ||> ||>>main() ||>>{ ||>>int inside; ||>>... ||>>} ||> ||>>_________________________ ||> ||> ||>>Our debate is which one of these ||>>two are initialized to zero if ||>>any. ||>None of them is. | |Um, no. outside is initialized to zero. | ||> ||>For further info RTFM. ||> | |Good idea. | Very good idea. Better yet, the manual specific to the compiler package *you* are using. On some older compilers, you needed to explicitly initialize globals in the file they were intended to be *defined* in. All other occurances of things like the declaration of "outside" (as above) were assumed to be a reference to an external that was defined in another file. If you didn't have a global initialized at least once, the symbol for it was never defined, and thus the link phase would fail. In newer compilers however, declarations like that in the original question above result in "outside" being global, it is defined in the file that contains the above declaration (it is not preceded with the word "extern"), and the space it occupies is initialized to zero. Regardless of what newer compilers do with globals however, IMHO it is best to explicitly initialize such variables if you expect them to start with a known value - even 0. Self-documenting code is a good practice. Now, "inside" is local to the function main and is an "auto" variable (it's space is on the stack), thus it is un-initialized (will contain whatever was in the portion of memory occupied by that variable when the stack frame is allocated at run-time). -- Jim Seymour | Medar, Inc. ...!uunet!medar!jseymour | 38700 Grand River Ave. jseymour@medar.com | Farmington Hills, MI. 48331 CIS: 72730,1166 GEnie: jseymour | FAX: (313)477-8897