Roman said:
Hello, All!
As far as I understand, function declaration with 'static' keyword
limits the access to these functions within the file where it declared. So,
my question is: where can it be used in real applications?
In every single translation unit.
For example, if you decide to have essentially "one function per module"
then this usually means that you have one "visible" function, i.e.
a function with external linkage which can be called from "everywhere".
Now, this function may become too large or may contain non-portable
parts, so you split off other functions. These functions reside within
the same translation unit but usually are not useful out of context or
should not be accessible from without as this would enable easy misuse
of the module. So, you do not want these functions to be "visible".
Using 'static' gives them internal linkage, et voila.
Another point are identifiers -- if you do not broadcast the name of
all functions into the global namespace, then you are less likely
to run into name clashes. This is, for example, important for
libraries; all the functions not intended for the user should not
pollute the namespace.
This becomes obvious if there are two libraries which both have the
externally useless function my_little_helper() and give you trouble
as they cannot be used together reliably.
So, the question really is: When do you _not_ want your functions to
have internal linkage?
Cheers
Michael