main.c:
Code:
static int foo(int);
int main ()
{
int result = foo(2);
printf("%i", result);
return 0;
}
foo.c:
Code:
extern int foo(int a) {
return a * 2;
}
This outputs 4.
What exactly is happening under the hood here?
I do know the following is happening:
1) Before we call a function, in this case, foo, we must declare it which is done so at the top of main.c
2) The declaration at the top says static which means: Mr Compiler, dont go looking in other files for foo's definition, look right here in main.c
3) Yet, the definition of foo itself is extern which means its available to anyone who calls it
This is a contradiction and I think its actually undefined behaviour which by chance returns 4.
Thoughts?