Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Is 'extern' necessary? Date: Fri, 10 Feb 2017 13:33:40 -0800 Organization: None to speak of Lines: 47 Message-ID: References: <4920b63e-c9ac-4ddb-96f4-5c45257f6689@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="be0e2eec6e3a3e421f62644bd2dd2876"; logging-data="5703"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DNeGnlOGYjY+NjuKIKtbn" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:t1CbwIAL9B5cwWekxM0+4gFaNSY= sha1:0DkbeC9lPZsl3FtwpwEgXfmwkfs= Xref: csiph.com comp.lang.c:103629 BartC writes: > On 10/02/2017 20:09, jameskuyper@verizon.net wrote: >> On Friday, February 10, 2017 at 1:41:10 PM UTC-5, Bart wrote: >>> On 10/02/2017 17:33, Keith Thompson wrote: >>>> BartC writes: >>>>> I've been trying to find out what the point of 'extern' is. >>>> >>>> N1570 6.9.2, tentative definitions. >>> >>> It mentions 'external definition'. What does that mean? >> >> Go up one level. Section 6.9 is titled "External definitions", 6.9p1 >> defines what an external declaration is, and 6.9p5 defines an >> external definition as an external declaration that is also a >> definition, referring back to 6.7p5 for the definition of >> "definition". >> >>> Presumably it can't mean a definition with 'extern', because if I write: >>> >>> extern int abc = 100; >> >> In 6.9, "external" means "outside of any function" (6.9p4), whereas >> in most other parts of the standard it refers to "external linkage". > > I remember that from a previous discussion. It comes up in K&R2 1.10 > (p31): "An external variable... must be defined outside of any function. > ...The variable must also be declared in each function that wants to > access it...". And it goes on to suggest using an explicit 'extern' > statement. > > I think that's just ramped up the confusion by a magnitude or so! That appears to be some unfortunate wording in K&R2. It implies (and the example shows) that the variables need to be declared *inside* each function that refers to them. In fact, the declaration merely needs to be visible. Note that the idea of header files has not yet been introduced at that point. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"