Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 (Fortune 01.1b1); site graffiti.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!ut-sally!ut-ngp!shell!graffiti!peter From: peter@graffiti.UUCP (Peter da Silva) Newsgroups: net.lang.c Subject: Re: Forward Referencing of Static Variables OK? Message-ID: <291@graffiti.UUCP> Date: Sat, 12-Oct-85 16:59:53 EDT Article-I.D.: graffiti.291 Posted: Sat Oct 12 16:59:53 1985 Date-Received: Tue, 15-Oct-85 06:41:43 EDT References: <365@tekcbi.UUCP> <717@inset.UUCP> Organization: The Power Elite, Houston, TX Lines: 44 Answer: no. At least not according to the available Ritchie documentation. > The orginal article asked what should happen in this sort of case: > > /***********************************/ > extern int xxx; > > f(){ > xxx = 1; > } > > static int xxx; /* `extra' information about xxx */ > /***********************************/ > > The ANSI committee had a lot of work to do on this one. Why? It's perfectly obvious. The scope of a "global scope" declaration is the entire file after the declaration. It is not known before the declaration. If the extern keyword is used, storage is assumed to be allocated elsewhere. If the static keyword is used, the name is local to the file (useful when building libraries). The above code is not correct 'C', since xxxx is redeclared. > There is an even worse issue than that: > > /***********************************/ > f(){ > { > extern int xxx; /* OH BOY!!! - where am I visible? */ > /* Am I really extern? */ > } > } > > y(){ > /* can I use xxx in here ???? */ > } > /***********************************/ No. The scope of a declaration within a block is the remainder of the block. xxx is known within the block, nowhere else. I don't know about Plauger, but this is all explained in various ancillary documents to the UNIX programmer's manual.