No. A function declaration (prototype or even the definition) can omit the keyword static
if it comes after another declaration of the same function with static
.
If there is one static
declaration of a function, its first declaration has to be static
.
It is defined in ISO/IEC 9899:1999, 6.7.1:
If the declaration of a file scope identifier for [...] a function contains the storage-class specifier static
, the identifier has internal linkage.
[...]
For an identifier declared with the storage-class specifier extern
in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration.
[...]
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
.
[...]
If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined.
So, e.g. this is valid:
static void foo(void);
void foo(void);
static void foo(void) { }
This one too:
static void foo(void) { }
void foo(void);
static void bar(void);
void bar(void) {}
But this code is incorrect:
void foo(void);
static void foo(void) { }
Normally you will and should have the static
in the prototypes too (because they usually come first).
void foo(); static void foo() { }
? – Pottedclang
lets me do it. I just modified my existing codebase to:void stall(int); ... static void stall(int count) {...};
It gives a warning, but compiles and works. With compilers, we can almost guarantee any particular thing won't work the same in all cases, which is why questions like this exist; to attempt to get at the actual info from behind the scenes, instead of "oh, it worked here, so I'll just assume..." otoh, SO is full of demonstrably false information, including in "accepted" answers, so I agree that in-depth personal testing is superior in almost all cases. – Sober