문제

I have 3 files:

in file1.h I declared:

#ifdef SYMBOLE
extern int const my_var;
#else
extern int my_var;
#endif

in file file2.c I defined:

int my_var;

and in file3.c I initialized my_var:

my_var = 4;

My question is, if I declared my_var like this way then my_var will be considered constant or variable especially if SYMBOLE is defined ?

도움이 되었습니까?

해결책

Line in file2.c is not definition, it is a declaration. (unless you initialize it)

So if SYMBOLE is defined, your variable will be conisdered constant and cause a compilation error in file2.c because of conflicting type declaration for variable my_var.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top