Declaring a global variable in C with .mm and .h files?
Hello computing peoples of the world!
I have a bunch of .mm with their respective .h files. I would like one global unsigned int variable that I could use throughout all the source files. Right now I'm trying to do this by开发者_如何学C placing this statement in one of the .h files:
extern unsigned int global_size_of_instrumental;
But I'm getting super strange errors such as:
Any ideas?
extern
is an indicator that the variable is defined somewhere else rather than "here".
Somewhere (preferably in a C file to avoid the possibility of multiple definitions), you will need just:
unsigned int global_size_of_instrumental;
You need to put this in only one of the .mm files:
unsigned int global_size_of_instrumental;
And then, in every other .mm you need to use (reference) it put:
extern unsigned int global_size_of_instrumental;
Done.
精彩评论