Reputation: 117
Can we use same function name in 2 different file in C by giving static? Like static myfunc() in file1.c and static myfunc() in file2.c. Will linker understand the scope or it will throw the error?
Upvotes: 8
Views: 2293
Reputation: 477640
Global names declared static
have internal linkage, which means that such a name is private to the translation unit. More specifically, within one translation unit, all static
declarations of a name refer to the same object or function, but in each translation unit, such a declaration refers to a distinct object or function. (By contrast, all names with external linkage refer to the same entity across the entire program.)
Upvotes: 3
Reputation: 72686
static
tells that a function or data element is only known within the scope of the compilation unit, so the answer to your question is Yes you will be able to declare a static function with the same name and even with the same signature in two different compilation unit.
Upvotes: 10