Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site aecom.UUCP Path: utzoo!linus!philabs!aecom!naftoli From: naftoli@aecom.UUCP (Robert Berlinger) Newsgroups: net.lang.c Subject: storage class ambiguity Message-ID: <223@aecom.UUCP> Date: Tue, 1-Nov-83 16:45:40 EST Article-I.D.: aecom.223 Posted: Tue Nov 1 16:45:40 1983 Date-Received: Fri, 4-Nov-83 01:59:20 EST Organization: Albert Einstein Coll. of Med., NY Lines: 64 There seems to be a slight ambiguity in the description of external variables in the C reference manual. (The C programming language, Kernighan & Ritchie, Prentice Hall 1978). To my knowledge the proper way to declare a global variable is to declare "int foo;" in one source file and declare "extern int foo;" in all the rest. However, according to the reference manual this seems unnecessary and you should be able to declare "int foo;" in all source files. The reference page 205, paragraph 10.2 states: > 10.2 External data definitions > An external data definition has the form > > data-definition: > declaration > > The storage class of such data may be extern (which is the > default) or static, but not auto or register. According to this, since data outside of a procedure is by default extern, you need not ever explicitly declare it as such. This is true in the case of most UN*X compilers that I've seen. Example: file 1: int foo = 8; file 2: int foo; No errors; foo will be initialized to 8. file 1: int foo; file 2: int foo = 8; No errors; foo will be initialized to 8. file 1: int foo = 8; file 2: int foo = 7; Multiply defined error from loader. file 1: extern int foo; file 2: extern int foo; Undefined _foo message from loader. file 1: extern int foo = 8; Compiler msg - cannot initialize external. The last two errors are the most important here. If extern is purported to be the default, then why do you get an error if you state it explicitly? Also, I've heard that IBM/370 compilers do not resolve the references and will create two seperate global cells. If this is true (that not all compilers resolve several global declarations) then the reference manual should not say that extern is the default. Rather, a null storage class outside of the program definition should mean declaration, and an extern storage class should mean definition. Robert Berlinger Systems Support Albert Einstein Coll. of Med. {philabs,esquire,cucard}!aecom!naftoli