🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2118

Re: Static function prototypes and definitions

#2118
From: Norman Diamond
Date: Tue, 13 Oct 1992 01:13
65 lines
3529 bytes
In article <1bcn2mINN680@news.aero.org> lmiller@aero.org (Lawrence H. Miller) writes:
>If I have a static function defined in a file, must the 
>prototype also have the word static?

The first prototype with file scope must say "static."
All prototypes with block scope that appear before the first prototype with
file scope must also say "static."

After the first prototype with file scope, later prototypes may either say
"static" or "extern" or may omit the storage class entirely.  Reasons:

ANSI 3.1.2.2, page 22 lines 16 to 18:  "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."  So it retains internal linkage from the first file scope
declaration, even if it says "extern" this time.

Same page, lines 20 to 21:  "If the declaration of an identifier for a
function has no storage-class specifier, its linkage is determined exactly
as if it were declared with the storage class specifier extern."  So by
this roundabout method, it again retains internal linkage.

>My reading of the standard is that the word static is forbidden in block
>scope declarations,

Where did you read that?  Section, page, and line numbers please.

>but gnu C requires it.

Sounds like it's probably right, depending on where the particular
declaration is located.

In article <bjEsPb0L@twinsun.com> eggert@twinsun.com (Paul Eggert) writes:
>I can't reproduce the problem that you describe.  Given the program
>	void f(void) { static void g(void); g(); }
>	static void g(void) {}
>`gcc -ansi -pedantic' (GCC 2.2.2) issues a diagnostic, as required by
>the C standard:
>	t.c: In function `f':
>	t.c:1: warning: invalid storage class for function `g'

Well then, you reproduced a different problem.  Of course, this doesn't
affect whether gcc conforms or not, because the standard allows conforming
implementations to issue spurious false misleading error messages.

>The proper way to write this is:
>	static void g(void);
>	void f(void) { g(); }
>	static void g(void) {}

That is a proper way.  Another proper way is the one gcc complained about.

>The GCC manual says:
>     Some users try to use `-pedantic' to check programs for strict ANSI
>     C conformance.  They soon find that it does not do quite what they
>     want: it finds some non-ANSI practices, but not all--only those
>     for which ANSI C *requires* a diagnostic.

Nope, it found a practice for which ANSI C doesn't require a diagnostic
and for which there is no good reason to issue a diagnostic.
Demand a refund for your copy of GCC :-)
--
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: <1992Oct13.011303.27314@nntpd.lkg.dec.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!taco!gatech!darwin.sura.net!haven.umd.edu!decuac!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
References: <1bcn2mINN680@news.aero.org> <bjEsPb0L@twinsun.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!taco!gatech!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: <1992Oct13.011303.27314@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: <1bcn2mINN680@news.aero.org> <bjEsPb0L@twinsun.com>
Date: Tue, 13 Oct 1992 01:13:03 GMT
Lines: 65