This message was edited by stober at 2005-9-30 11:20:21
: Hi, I've recently noticed a wide use of static varibles, functions, class etc'. When I've learnt about static uses, the explainations were extremely vague and no examples were given. Can someone tell me what the definition of static is?
:
One other point others have not mentioned. A static function can only be called from other functions within the same *.c or *.cpp file in which it resides. That means static function foo() cannot be called from a function in another source file. It also means two source files can declare static function(s) with the same name
// file a.c
static int foo()
{
return 0;
}
// file b.c
static char* foo(int x)
{
char* p = malloc(x);
return p;
}
When the above two files are compiled and linked into the same program, the linker will not generate duplicate function declaractions because the functions are static and visible only within the file in which they reside.