Can we use the same function name in 2 different files in C, specifying static?

Can we use the same function name in 2 different C files by setting static? Like static myfunc () in file1.c and static myfunc () in file2.c. Will the linker understand the area or will it cause an error?

+4
source share
3 answers

static reports that the element or data element is known only within the compilation area , so the answer to your question is: β€œYes, you can declare a static function using the same name and even with the same signature in two different compilation units.

+7
source

, static.

+5

Declared global names staticare internally referenced, which means that such a name is private to the translation unit. More specifically, within a single translation unit, all declarations of a staticname refer to the same object or function, but in each translation unit such an announcement refers to a separate object or function. (In contrast, all external-referenced names refer to the same object throughout the program.)

+1
source

Source: https://habr.com/ru/post/1614234/


All Articles