Next: Arrays as Parameters, Previous: Forward Function Declarations, Up: Function Definitions [Contents][Index]
The keyword static
in a function definition limits the
visibility of the name to the current compilation module. (That’s the
same thing static
does in variable declarations;
see File-Scope Variables.) For instance, if one compilation module
contains this code:
static int
foo (void)
{
…
}
then the code of that compilation module can call foo
anywhere
after the definition, but other compilation modules cannot refer to it
at all.
To call foo
before its definition, it needs a forward
declaration, which should use static
since the function
definition does. For this function, it looks like this:
static int foo (void);
It is generally wise to use static
on the definitions of
functions that won’t be called from outside the same compilation
module. This makes sure that calls are not added in other modules.
If programmers decide to change the function’s calling convention, or
understand all the consequences of its use, they will only have to
check for calls in the same compilation module.