Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site tekcbi.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!tektronix!tekcbi!jimpr
From: jimpr@tekcbi.UUCP
Newsgroups: net.lang.c
Subject: Forward Referencing of Static Variables OK?
Message-ID: <365@tekcbi.UUCP>
Date: Tue, 1-Oct-85 13:45:09 EDT
Article-I.D.: tekcbi.365
Posted: Tue Oct  1 13:45:09 1985
Date-Received: Thu, 3-Oct-85 04:57:22 EDT
Sender: jimpr@tekcbi.UUCP
Organization: Tektronix, Beaverton OR
Lines: 38

A C compiler we are using was designed in such a way that the following
code would not compile:

	extern int thing;	/* don't know yet if thing is static or not */

	main() {
		printf("%d  %d\n", thing, increment(thing));
	}

	static int thing = 0;	/* now we know that it's static */

	int increment(x)
		int x;
	{
		return(++x);
	}

Now the situation is basically this:  the compiler complains because 
"thing" is first declared external int, referenced (as extern int) and
then declared (the designers say "re-declared") static int after the
reference.

Their contention that not allowing this type of forward referencing of
static variables is consistent with "The C Programming Language", (K. & P.).

Now I know this program works quite well on our VAX running 4.2BSD, our
Pyramid running 4.2BSD & System V, and other users say that a few PC's
running Microsoft C and Lattice C are quite happy with this construction.
They all make "thing" static (ie, local to the file "thing" is defined in).

What say you all?  Is there any language in K & P which would dissuade them?
Thanks!

               --Jim Prouty	Tektronix, Inc

uucp:      {ucbvax,decvax,pur-ee,ihnss,chico}!tektronix!tekcbi!jimpr
ARPAnet:   tekcbi!jimpr.tek@rand-relay
CSnet:     tekcbi!jimpr@tek