Another related question:
Say I have the following 3 files:
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
But, would it be correct to instead drop defining the globalCommonVariable, and instead just do like this in the header:Code:extern 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.Code:int globalCommonVariable;
However...is it safe, and is it correct according to standards and all that stuff?