Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bloom-beacon!think!ames!amdcad!sun!imagen!auspyr!john From: john@auspyr.UUCP (John Weald) Newsgroups: comp.lang.c Subject: Scope of externals definitions Message-ID: <8959@auspyr.UUCP> Date: Tue, 8-Sep-87 13:52:21 EDT Article-I.D.: auspyr.8959 Posted: Tue Sep 8 13:52:21 1987 Date-Received: Thu, 10-Sep-87 05:39:27 EDT Reply-To: john@auspyr.UUCP (John Weald) Organization: Austec, Inc. San Jose Lines: 53 What does the dpANSI standard have to say about the following? The following program compiles (does not link of course) on 3b5 SVR2: In the file foo.c: main() { extern int foo; foo++; f(); } f() { /* Same "foo" as above */ foo++; } K&R have this to say on the subject: Page 76, section 4.5 "Scope Rules": The scope of an external variable lasts from the point at which it is declared in a source file to the end of that file. ... (Some discussion about declarations deleted) On the other hand, the lines extern int sp; extern double val[]; *declare* for the rest of the file that sp is an int and that val is a double array. Page 206, section 11.1 "Lexical Scope": The lexical scope of identifiers declared in external definitions persists from the definition through the end of the source file in which they appear. On our uVAX running VMS 4.5 (C v2.3) the variable "foo" only has scope within the function block. It gives the message: "foo" is not declared within the scope of this usage The key words appear to be "though the end of the file." Any comments? John Weald, Austec, Inc. San Jose. -- UUCP: {styx,imagen,dlb,gould,sci,altnet}!auspyr!john