如果变量在 file1.c
中定义为 volatile int x
并在 file2 中定义为
(而不是 extern int x
会发生什么。 cextern volatile int x
)?编译器是否有机会知道 x
是易变的并在 file2.c
中编译。
最佳答案
编译器只知道当前translation unit (基本上是包含所有内容的当前源文件),没有别的。
如果未使用正确的类型声明 extern
变量,则会出现未定义的行为。
关于c - 将 volatile int 变量定义为 extern int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42394143/