c - 将 volatile int 变量定义为 extern int

标签 c gcc

如果变量在 file1.c 中定义为 volatile int x 并在 file2 中定义为 extern int x 会发生什么。 c(而不是 extern volatile int x)?编译器是否有机会知道 x 是易变的并在 file2.c 中编译。

最佳答案

编译器只知道当前translation unit (基本上是包含所有内容的当前源文件),没有别的。

如果未使用正确的类型声明 extern 变量,则会出现未定义的行为。

关于c - 将 volatile int 变量定义为 extern int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42394143/

相关文章:

python - 在 OS X 中运行进程,查找启动进程

c++ - vsnprintf 和 gcc

c - 如何在 GCC 中编译 C 程序以在 WinDbg 中启用调试?

python - 安装 Pillow 错误 : Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

c - 如何从 char 值 c 中删除子域

c - 使用语句 fflush(stdin) 有多合适?

C 结构--错误 : parameter name omitted

c - 可变长度霍夫曼码的比特流 - 如何写入文件?

c++ - 为什么命名空间内的自由函数不明确?

c++ - g++ 调用的等效 gcc 标志