Hello.

Disclaimer: I'm no expert at those things, so please be patient with me;)

Quote Originally Posted by sanddune008 View Post
If i declare and define a function as
void add() in a.c won't this as well be private to the file?
Unless I declare the same in a a.h and include the same in b.c?
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).

Let me demonstrate this with really simple application, created from two separate files.

a.c
Code:
#include <stdio.h>

int
main( int    argc,
      char **argv )
{
    /* b_print is defined in b.c */
    b_print( "Print this" );

    return( 0 );
}
b.c
Code:
#include <stdio.h>

void
b_print( const char *string )
{
    printf( "OUTPUT: >> %s <<\n", string );
}
Now if we compile and link this application like this:
Code:
gcc -Wall -o b.o -c b.c
gcc -Wall -o a.o -c a.c
gcc -Wall -o example b.o a.o
the second command will warn us about implicit declaration of b_print function, but other that that, application will compile and link cleanly.

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.