Disclaimer: I'm no expert at those things, so please be patient with me;)
Actually, if you omit "static" in front of the function definition, compiler will export it and the linker will be able to link against it, no matter where the function has been declared (if at all).
Originally Posted by sanddune008
Let me demonstrate this with really simple application, created from two separate files.
main( int argc,
char **argv )
/* b_print is defined in b.c */
b_print( "Print this" );
return( 0 );
Now if we compile and link this application like this:
b_print( const char *string )
printf( "OUTPUT: >> %s <<\n", string );
the second command will warn us about implicit declaration of b_print function, but other that that, application will compile and link cleanly.
gcc -Wall -o b.o -c b.c
gcc -Wall -o a.o -c a.c
gcc -Wall -o example b.o a.o
Now, if you insert "static" in front of b_print function definition and rebuild this application once again using the same commands as before, the first command will warn you about b_print function being defined but not used. Second command will produce the same warning as before. And the link command will fail, moaning about undefined reference to b_print.
I hope this explanation makes things a bit more clear.
BTW, I used gcc as a compiler since this is what I have at hand. Warnings may differ if you'll be using different compiler.