Forward Referencing of Static Variables OK?

jimpr at tekcbi.UUCP jimpr at tekcbi.UUCP
Wed Oct 2 03:45:09 AEST 1985


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 at rand-relay
CSnet:     tekcbi!jimpr at tek



More information about the Comp.lang.c mailing list