Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site asgb.UUCP Path: utzoo!linus!decvax!ucbvax!ucdavis!lll-crg!seismo!hao!asgb!devine From: devine@asgb.UUCP (Robert J. Devine) Newsgroups: net.lang.c Subject: Re: Forward Referencing of Static Variables OK? Message-ID: <792@asgb.UUCP> Date: Thu, 10-Oct-85 15:24:11 EDT Article-I.D.: asgb.792 Posted: Thu Oct 10 15:24:11 1985 Date-Received: Sat, 12-Oct-85 07:29:07 EDT References: <365@tekcbi.UUCP> <268@ssc-vax.UUCP> Organization: Burroughs Corp. ASG, Boulder Colo. Lines: 28 > From the way I read K&R, the "static" keyword is redundant, unless > it is inside a function. In other words, "static int thing;" is > equivalent to "int thing;" unless the declaration takes place inside > a function. (Any comment on that??) It is not equivalent. Declaring a variable as "static int abc;" means that "abc" is not exported to the linker. "int def;" is exported and hence can be referenced in other files. The default storage class is "extern". > Then, the "extern" keyword specifies that the variable declared is > contained in some other program unit (usually outside the current > function, but in this case, outside the current file). I have seen > nothing in K&R that says that this variable can be redeclared inside > the current program unit. In other words, if the compiler writer > wants to be nice, he will let you redeclare it, but he/she does > not have to. (Any further comments??) To be pedantic, there are two types declarations that are possible for external variables -- one that defines and one that references. As an example, what does "extern int abc;" mean in a file? That is, is it referencing a definition of "int abc" from a different file? Or is this where abc is defined? Difference compilers do different things in this case. A portable (?) way of declaring variables that are used in different files is to have one declaration be the definition. To do this, initialize it and don't use "extern" in its declaration. Bob