Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tdatirv!sarima From: sarima@tdatirv.UUCP (Stanley Friesen) Newsgroups: comp.std.c Subject: Re: 3.7.2 External Object Definitions Keywords: external,linkage,declaration,definition Message-ID: <131@tdatirv.UUCP> Date: 6 Feb 91 21:24:19 GMT References: Reply-To: sarima@tdatirv.UUCP (Stanley Friesen) Organization: Teradata Corp., Irvine Lines: 44 In article eyal@echo.canberra.edu.au (Eyal Lebedinsky) writes: >I tried gnu (1.39) which I hope is ANSI by now. It likes this one: > >(1) extern int i7; >(2) static int i7 = 1; Well, then it is wrong. (1) is a tentative definition with *external* linkage. As such it is incompatible with (2), which is illegal in the same scope. [(1) is external by 3.1.2.2 paragraph 4, the incompatibility is required by paragraph 7]. >It hates this one: > > static int i7; /* tentative definition, internal linkage */ >(3) extern int i7 = 1; Beep, Gnu is wrong again! This is actually the correct way to do it. (3) could also be: static int i7 = 1; The original (3) is legal due to the statement that makes (1) external. In essence, if an 'extern' appears *after* a 'static' it is a backwards reference to the 'static' declaration, otherwise it is an external declaration. The prior declaration is clearly a tentative definition of a variable with internal linakage by 3.7.2 paragraph 2. The examples in 3.7.2 actually support this treatment if read carefully. >Microsoft 5.1 likes both, but I wouldn't trust it much. Well, at least it is only half wrong. It is *required* to diagnose (2) if it follows (1). >Q: what should the comment on the right say for (1,2,3) in the sense on >the examples at the end of 3.7.2? (1) /* tentative definition, external linkage */ (2) /* undefined - linkage disagreement, would be internal linkage */ (3) /* definition, refers to previous (internal linkage) */ Sigh, well, I guess gcc isn't as ANSI as it likes to claim. -- --------------- uunet!tdatirv!sarima (Stanley Friesen)