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?
how to use static function defined in one file in another file is that impposiible in 'c ' the static function. This function would be of external linkage and would invoke the static function internally. function in the other file from which you want accs to the static fun. Replies have been disabled for this discussion. Use of static ?
Static functions in C. Unlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static. Another reason for making functions static can be reuse of the same function name in other files.
The “ static ” keyword before a function name makes it static. For example, below function fun () is static. Unlike global functions in C, access to static functions is restricted to the file where they are declared.
Prerequisite : Static variables in C. In C, functions are global by default. The “static” keyword before a function name makes it static. For example, below function fun() is static.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With