Another related question:
Say I have the following 3 files:
-main.c
-writeFunction.c
-header.h
And I want main.c and writeFunction.c to have a common global variable.
So that I can modify the variable in main, and then the variable in the function in "writeFunction.c" would be updated as well.
One possibilty is to define the variable in for example main, and in "header.h", include
Code:
extern int globalCommonVariable;
But, would it be correct to instead drop defining the globalCommonVariable, and instead just do like this in the header:
Code:
int globalCommonVariable;
I have compiled and tested it, and if I do it like this, it works, and the variable is shared, with only 1 definition, and no use what so ever of extern.
However...is it safe, and is it correct according to standards and all that stuff?