Article View: comp.std.c
Article #2129Re: Static function prototypes and definitions
From: Norman Diamond
Date: Thu, 15 Oct 1992 01:14
Date: Thu, 15 Oct 1992 01:14
57 lines
3565 bytes
3565 bytes
In article <1bi565INNgc1@news.aero.org> lmiller@aero.org (Lawrence H. Miller) writes:
>In article <bjFLFApU@twinsun.com> eggert@twinsun.com (Paul Eggert) writes:
>> void f(void) { void g(void); g(); }
>> static void g(void) { }
>>has undefined behavior because g has both external and internal linkage.
>>See ANSI C 3.1.2.2 (Linkages of Identifiers).
That is correct.
> 3.1.2.2 Linkage of Identifiers
> If the declaration of a file scope identifier for an
> object or a function contains the storage-class specifier
> static, the identifier has internal linkage.
The standard should have said, "the identifier is declared to have internal
linkage" because the actual effect isn't known yet.
> If the declaration of an identifier for an object or
> function contains the storage-class specifier extern, the
> identifier has the same linkage as any visible declaration
> of the identifier with file scope.
Yes but at the time of the first declaration, there is no visible declaration
with file scope. The standard says "If there is no visible declaration with
file scope, the identifier has external linkage" but should have said "is
declared to have external linkage."
> [It goes on to say that if there is no other storage-class
> specifier, it is extern.]
Yes, and that applies to the first declaration.
>So the question becomes, what is the definition of "visible
>declaration"? We look back in 3.1.2.1 and we find:
> Every other identifier has scope determined by the
> placement of its declaration...If the declarator or type
> specifier...appears outside of any block or list of
> parameters,, the identifier has file scope, which terminates
> at the end of the translation unit.
>Now I interpret this to mean what it says: a function definition has
>FILE SCOPE, i.e., from the START to the END of the file.
The first identifier "g" has block scope. The second identifier "g" has
file scope. The second one's scope (file scope) ends at the end of the
translation unit, exactly as in the text you quoted. Why didn't you quote
the text that says where the scope starts, instead of guessing? Lines 39
to 42 on the same page. Since this isn't a tag or enumeration constant,
the final sentence applies: "Any other identifier has scope that begins
just after the completion of its declarator."
And finally, back to the linkage section: "If, within a translation unit,
the same identifier appears with both internal and external linkage, the
behavior is undefined."
--
Norman Diamond diamond@jit081.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
"Yeah -- bad wiring. That was probably it. Very bad."
Technical Details
Message-ID:
<1992Oct15.011402.19588@nntpd.lkg.dec.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!news.byu.edu!hamblin.math.byu.edu!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!haven.umd.edu!decuac!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamondReferences:
<1992Oct13.011303.27314@nntpd.lkg.dec.com> <1bhhe5INNf8f@news.aero.org> <bjFLFApU@twinsun.com> <1bi565INNgc1@news.aero.org>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!news.byu.edu!hamblin.math.byu.edu!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!haven.umd.edu!decuac!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond From: diamond@jit345.bad.jit.dec.com (Norman Diamond) Subject: Re: Static function prototypes and definitions Message-ID: <1992Oct15.011402.19588@nntpd.lkg.dec.com> Sender: usenet@nntpd.lkg.dec.com (USENET News System) Reply-To: diamond@jit.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo References: <1992Oct13.011303.27314@nntpd.lkg.dec.com> <1bhhe5INNf8f@news.aero.org> <bjFLFApU@twinsun.com> <1bi565INNgc1@news.aero.org> Date: Thu, 15 Oct 1992 01:14:02 GMT Lines: 57