简体   繁体   中英

Calling a static function with global variables in C

I have a static function defined in ac 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?

Static variables defined at the outermost level of a source file have file scope , ie: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM