dolphin a écrit :
On Nov 5, 4:57 pm, Michael DOUBEZ <michael.dou...@free.frwrote:
>dolphin a écrit :
>>I read a .cpp files,find that
static void fun(void){......}
int main()
{
.........
}
What does this static function mean?Is it the same as the static
function in a class?
Technically, this means the name of the function won't be exported so
you can reuse it in more than one compilation unit.
From the programmer point of view, this means the function won't be
called by tis name outside the compilation unit.
An alternative is to use an unnamed namespace.
Do you mean you just can use this function in that cpp file?And you
cannt use it in another cpp file?
What I mean is that the name of the function is not exported in the
symbol table so you cannot link against it outside the cpp file it is
defined in.
That doesn't mean it cannot be used, you could use through is function
pointer by example. But not with its name. Try it out on an example.
main.cpp
-----------------------
extern int cu_function();
int main()
{
return cu_function();
}
cu.cpp
-----------------------
//uncomment static to see what happen
//static
int cu_function()
{
return 0;
}
-----------------------
Then
g++ main.cpp cu.cpp
Michael