Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!qantel!dual!lll-crg!seismo!brl-tgr!tgr!gwyn@BRL.ARPA From: gwyn@BRL.ARPA (VLD/VMB) Newsgroups: net.lang.c Subject: Re: Forward Referencing of Static Variables OK? Message-ID: <1919@brl-tgr.ARPA> Date: Sat, 5-Oct-85 21:16:57 EDT Article-I.D.: brl-tgr.1919 Posted: Sat Oct 5 21:16:57 1985 Date-Received: Mon, 7-Oct-85 05:40:35 EDT Sender: news@brl-tgr.ARPA Lines: 52 Actually, I no longer remember why I thought that extern int thing; ... static int thing = 0; is legal (according to X3J11). My reading today is that the first declaration gives "thing" external linkage and the second declaration gives it static linkage, which is a contradictory declaration. I think I must have missed the description of linkage in the X3J11 document when I first looked this up. My current position is that this is NOT legal usage. Sorry for the mistake; thanks for pointing it out. Minow sent me another illustration: func() { extern char *foo(); ... } ... static char *foo() { ... } which my latest attempt at understanding X3J11 tells me is illegal, since without a file-scope definition in effect, the "extern" forces external linkage whereas the "static" specifies static linkage. In this case, adding static char *foo(); at the front of the file will keep the "extern" from having an effect on the linkage type. K&R is not nearly as thorough in this whole area as the X3J11 specification, although X3J11 seems to be compatible with the intent of K&R. Needless to say, there are a number of compilers around today that do not enforce these rules. Programmers: Declare everything before you use it. If it is a file-static (private) object/function, call it "static" whenever you declare it. If it is an external (public) object/function, not defined in the same file, call it "extern". If it is external but defined in the same file, you may call it "extern" in all declarations other than the defining one. Don't call anything both "extern" and "static". (X3J11 is actually more complex than this, but these rules should keep you out of trouble.)