Path: utzoo!attcan!uunet!husc6!bloom-beacon!mit-eddie!ll-xn!ames!oliveb!pyramid!markhall From: markhall@pyramid.pyramid.com (Mark Hall) Newsgroups: comp.lang.c Subject: Re: Help needed with #include problems Message-ID: <24341@pyramid.pyramid.com> Date: 23 May 88 18:26:21 GMT References: <28400001@ntvax> <6104@sigi.Colorado.EDU> <2955@ihlpe.ATT.COM> <998@mit-caf.UUCP> Reply-To: markhall@pyramid.UUCP (Mark Hall) Organization: Pyramid Technology Corp., Mountain View, CA Lines: 29 In article <998@mit-caf.UUCP> vlcek@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@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