Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top