Just above and below main()

Christopher R Volpe volpe at camelback.crd.ge.com
Mon Apr 15 23:08:13 AEST 1991


In article <111 at hdwr1.medar.com>, jseymour at medar.com (James Seymour) writes:
|>Very good idea.  Better yet, the manual specific to the compiler package
|>*you* are using.  On some older compilers, you needed to explicitly
                            ^^^^^
By "older" I assume you mean "broken"???

|>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.

The behavior you are describing does not correspond to the C language
described either by ANSI or by K&R1. It doesn't make much sense to
point out every possible way a compiler can do the wrong thing whenever
you tell someone what the language guarantees, IMHO.

|>  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.

Agreed.

|>-- 
|>Jim Seymour				| Medar, Inc.
|>...!uunet!medar!jseymour		| 38700 Grand River Ave.
|>jseymour at medar.com			| Farmington Hills, MI. 48331
|>CIS: 72730,1166  GEnie: jseymour	| FAX: (313)477-8897
                                                       
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.lang.c mailing list