main.h
extern int array[100];
main.c
#include 'main.h' int array[100] = {0}; int main(void) { /* do_stuff_with_array */ }
In the main.c module, the array is defined, and declared. Does the act of also having the extern statement included in the module, cause any problems?
I have always visualized the extern statement as a command to the linker to ‘look elsewhere for the actual named entity. It’s not in here.
What am I missing?
Thanks.
Evil.
The correct interpretation of
externis that you tell something to the compiler. You tell the compiler that, despite not being present right now, the variable declared will somehow be found by the linker (typically in another object (file)). The linker will then be the lucky guy to find everything and put it together, whether you had some extern declarations or not.To avoid exposure of names (variables, functions, ..) outside of a specific object (file), you would have to use
static.