I have the following two files:
file1.c
int main(){
foo();
return 0;
}
file2.c
void foo(){
}
Can I compile and link the two files together so the file1.c will recognize the foo function without adding extern?
Updated the prototype.
gcc file1.c file2.c throws: warning: implicit declaration of function foo.
You don’t need an
extern, but file1.c must see a declaration thatfoo()exists. Usually this declaration is in a header file.To add a forward declaration without using a header file, simply modify file1.c to: