Reputation: 6573
What will happen if a variable is defined as volatile int x
in file1.c
and extern int x
in file2.c
(instead of extern volatile int x
)? Is there a chance for compiler to know that x
is volatile and compile as such in file2.c
.
Upvotes: 1
Views: 406
Reputation: 409432
The compiler only have knowledge of the current translation unit (basically the current source file with all includes), nothing else.
If an extern
variable is not declared using the correct type, then you will have undefined behavior.
Upvotes: 8