Help needed with #include problems

Mark Hall markhall at pyramid.pyramid.com
Tue May 24 04:26:21 AEST 1988


In article <998 at mit-caf.UUCP> vlcek at mit-caf.UUCP (Jim Vlcek) writes:

>I am under the impression that there is nothing wrong with having an
>``extern'' reference *and* a variable definition in the source file,
>and in fact I have done so in all of my C programming.  
>-- 
>Jim Vlcek
>vlcek at caf.mit.edu
>!{ihnp4,harvard,seismo,rutgers}!mit-eddie!mit-caf!vlcek

Your practice is OK according to K&R, pg 77:

	There must be only one `definition' of an external variable among
	all the files that make up the source program; other files may
	contain EXTERN declarations to access it.  (There may also
	be an EXTERN declaration in the file containing the definition).

On a related note, it's funny to watch how different compilers react to:
	main() {
		register int a;
		extern   int a;
	}
Some ignore the register directive and map `a' to some global variable
of the same name.  Others ignore the extern directive and create
local references to `a'.  I never could find out from K&R if this was 
an error, or if the `extern' should be ignored, or what.  Can anyone 
comment?  Just the facts, please.

-Mark Hall



More information about the Comp.lang.c mailing list