🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2127

Re: Static function prototypes and definitions

#2127
From: Lawrence H. Miller
Date: Wed, 14 Oct 1992 21:58
59 lines
2398 bytes
In article <bjFLFApU@twinsun.com> eggert@twinsun.com (Paul Eggert) writes:
>To answer Miller's question, the program
>
>       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).

Hmmm.  Perhaps not:

	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.
		
		[So g has internal linkage.]

	  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.

	[It goes on to say that if there is no other storage-class
	specifier, it is extern.]


So the question becomes, what is the definition of "visible
declaration"?  We look back in 3.1.2.1 and we find:

	3.1.2.1  Scopes of Identifiers

	  An identifier is visible (i.e., can be used) only within
	a region of program text called its scope...

	  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 declaration of g within f has the same linkage as
	the file scope definition of g, i.e., internal.]

So:
>
>       void f(void) { void g(void); g(); }
>       static void g(void) { }

should be valid, not undefined.

-- 
Larry Miller		The Aerospace Corporation
lmiller@aero.org	PO Box 92957		
310-336-5597		LA, CA 90009-2957
Technical Details
Message-ID: <1bi565INNgc1@news.aero.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!destroyer!sol.ctr.columbia.edu!usc!news.aero.org!lmiller
References: <1992Oct13.011303.27314@nntpd.lkg.dec.com> <1bhhe5INNf8f@news.aero.org> <bjFLFApU@twinsun.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!destroyer!sol.ctr.columbia.edu!usc!news.aero.org!lmiller
From: lmiller@aero.org (Lawrence H. Miller)
Newsgroups: comp.std.c
Subject: Re: Static function prototypes and definitions
Date: 14 Oct 1992 21:58:29 GMT
Organization: The Aerospace Corporation, El Segundo, CA
Lines: 59
Message-ID: <1bi565INNgc1@news.aero.org>
References: <1992Oct13.011303.27314@nntpd.lkg.dec.com> <1bhhe5INNf8f@news.aero.org> <bjFLFApU@twinsun.com>
NNTP-Posting-Host: palomar.aero.org