I have a static function defined in a c file that uses global static variables of the file. If I call the function from another file and I define the same static global variables but with different values, will it use the values from the original file or from the other file? If not, is there a way to use global parameters in a function I'm calling from different files without receiving them as inputs?
1 Answer
Static variables defined at the outermost level of a source file have file scope, i.e.: they are only visible in that file.
As an example, if you have a source file foo.c:
static int var;
and another one bar.c:
static int var;
There are two different copies of a variable with the name var. Each copy is only visible in the file in which it is defined.
1 Comment
Jeroen3
Try to avoid naming like this, name them foo_var and bar_var. You will thank yourself when debugging.
staticqualified?