🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1589

Re: Declarations with more/less detail, or "static" functins.

#1589
From: Doug Gwyn
Date: Sun, 12 Aug 1990 18:51
43 lines
2086 bytes
In article <84313@cc.utah.edu> ORCUTT@cc.utah.edu writes:
>static void func(void);     /* Declaration. */
>..
>static void func(void)     /* Definition. */
>{
>..
>H & S seem to indicate that the first "static" is illegal.

No, it's fine.

>If I remove it, the declaration will default to type "extern", ...

Yes, assuming that there is not another static-linkage declaration in scope.

>If I omit the "static" on the definition, these compilers will also
>declare the function "static" from the previous declaration.

Yes, also the standard requires that if there is an explicit "extern".
"extern" doesn't really mean "external linkage"; it means more "external
linkage if not already known to have static linkage".  (For objects rather
than functions, this is true for explicit "extern" but not for omitted
storage class.)  This mess has historical origins.  At least section 3.1.2.2
of the C standard is quite explicit about the official linkage rules.

>Is there an ANSI approved way to declare a function that
>will be "static" in a file before it is defined?

Sure; include the "static" storage-class specifier.

>The High-C way seems more in tune with the standard, which
>states that a declaration can "add detail" to an earlier one;

? The standard does not say that.

>... are the declarations
>double cos(double x);
>and
>double cos();
>compatible?

Yes, in the sense that having them both in scope does not violate any
constraint of the standard.  In the case of cos(), #including <math.h>
is the recommended way to declare the function.
Technical Details
Message-ID: <13538@smoke.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn
References: <84313@cc.utah.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn
From: gwyn@smoke.BRL.MIL (Doug Gwyn)
Newsgroups: comp.std.c
Subject: Re: Declarations with more/less detail, or "static" functins.
Message-ID: <13538@smoke.BRL.MIL>
Date: 12 Aug 90 18:51:43 GMT
References: <84313@cc.utah.edu>
Organization: U.S. Army Ballistic Research Laboratory, APG, MD.
Lines: 43