Why would I ever code a function as "static" such as:
static int myfunction(int arg1, int arg2)
{
do some stuff here...
}
Do this specification must have to do with the visibility of the function within a single source file and/or across multiple source files in the same project? Or, are the variables within the function affected in some way?
Seems to me the static specifier on a function means nothing.
Thanks.
Quote from: PhilG57 on December 28, 2013, 03:59:41 PM
Why would I ever code a function as "static" such as:
static int myfunction(int arg1, int arg2)
{
do some stuff here...
}
Do this specification must have to do with the visibility of the function within a single source file and/or across multiple source files in the same project?
Correct, a function declared as
static is only visible with the same source file. That means you can not call such a function from a different C file of the same project, as the linker will not include any public information into the object file...
QuoteSeems to me the static specifier on a function means nothing.
See above...
Ralf
Got it. So the static specification on a function aids documentation by ensuring the function will not be called outside of the current compilation unit. Many thanks.