Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use same function name in 2 different file in C by giving static?

Tags:

c

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?

like image 932
Priyank Kumar Dalal Avatar asked Nov 03 '15 08:11

Priyank Kumar Dalal


People also ask

How to use static function defined in one file in another file?

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 ?

Why do we use static functions in C?

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.

What is the static keyword before a function name in C?

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.

What is static variable in C with example?

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.


1 Answers

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.

like image 133
aleroot Avatar answered Oct 11 '22 12:10

aleroot