I have some global variables that I need to share on multi source files. I have read How do I share variables between different .c files? and do as following:
fileA.h
:
extern int a;
fileA.c
:
int a;
// using a variable here
Everything compile well and work fine. But because I program on multithread environment, so I put volatile
keyword before each variable. so now is :
fileA.h
:
extern volatile int a;
fileA.c
:
int a;
// using a variable here
But when I use this way, I meet error when compiling:
error: conflicting type qualifiers for ‘a’ in file included from fileA.c:4:0:
Please explain for me why, and how to fix this? Should we use volatile
in this case?