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

Doug Gwyn gwyn at smoke.BRL.MIL
Mon Aug 13 04:51:43 AEST 1990


In article <84313 at cc.utah.edu> ORCUTT at 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.



More information about the Comp.std.c mailing list