What is the result of mixing an extern function declaration and static function definition?
Firstly, by way of example, let's see the file called foo.c below:
Code:
extern int foo(int);
extern int foo(int a){
return a;
}
We have declared and consequently defined an extern function called foo. What this means is that the function can be called from other .c files (Yes, best practice says the declaration should go in a header but for simplicity lets assume no header)
Secondly, by way of example, let's see the file called bar.c below:
Code:
static int bar(int);
static int bar(int a){
return a;
}
We have declared and consequently defined a static function called bar. What this means is that the function cannot be called from other .c files (Yes, best practice says the declaration should go in a header but for simplicity lets assume no header)
Thirdly, by way of example, let's see the file called mixedFoo.c below:
Code:
extern int mixedFoo(int);
static int mixedFoo(int a){
return a;
}
The translation unit wont compile and GNU GCC gives an error that "static declaration of "mixedFoo" follows non-static declaration.
Finally, by way of example, let's see the file called mixedFoo2.c below:
Code:
static int mixedFoo2(int);
extern int mixedFoo2(int a){
return a;
}
This does not cause an error as case 3 above? Also, mixedFoo cannot be called from main.c. What exactly is happening under the hood in case 3 and 4?