[comp.std.c] "static" keyword used with function names

ORCUTT@cc.utah.edu (07/24/90)

I have a question about the incarnation of the "static" keyword
that tells C that a function or variable name is only visible in
the current file.  If I write

static int func(void);     /* A declaration */

.
.
.

static int func(void)      /* A definition */
{
/* do something */
return something;
}

H & S have a passage that seems to say that the "static" on
the declaration is illegal.  If I omit it, however, it would seem
that the function would be defaulted to type "extern" and then
the definition of type "static" would conflict with the declaration.
My Turbo-C and MSC compilers seem to allow the "static" in the 
delcaration, but my Metaware compiler complains.  So, how do
I correctly declare a function name "static" if I want
to declare the name earlier in the file that its definition?

gwyn@smoke.BRL.MIL (Doug Gwyn) (07/27/90)

In article <79253@cc.utah.edu> ORCUTT@cc.utah.edu writes:
>static int func(void);     /* A declaration */
>...
>static int func(void)      /* A definition */
>{
>...
>}

This is fine, so long as both these occur at file scope.  A block-scope
function declaration must not include the "static" storage-class specifier.

If you were to omit the first "static", that "func" would have external
linkage (assuming no previous internal-linkage declaration were visible
at that point), which is not what you want.  (The behavior when the same
identifier has been declared in the same scope with both internal and
external linkage is undefined, i.e. not something to rely on.)