I've discussed this somewhat in the C++ part of the forum as well, but I want to discuss the subject further in C, so I made a thread here.
The question is as simple as this:
If I want to share a global variable over 2 source files, could I just include this headerfile in both my files?
I have compiled it, and it works.Code:#ifndef MOFF #define MOFF int test; // Global variable to be used in 2 files #endif
The question is, is it legal, and more over, is it considered ok as a programming practice?
I guess part of the question is, is this a declaration or definition?
I tried to compile the following program:Code:int test;
And this compiled, linked and ran..and gave me output "50".Code:int test; int test=50; int test; int main(int argc, char *argv[]) { printf("%d\n", test); system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks


