我试图在同一个项目的另一个 C 源文件中使用我在 main.c 中声明的预处理器变量,但我得到一个编译时错误,包含在 main.c 中: undefined symbol '我的符号'。现在,关于在包含它的文件之外使用 #define
的规则是什么?
最佳答案
Now, what are the rules concerning the use of #define out side the file in which it is contained
#define
在其文件外是不可见的。使其在定义它的文件之外可见的唯一方法是包含该文件。
所以看起来您应该将它放在 main.c
和其他文件都包含的 header 中。
关于c - #define 变量的范围是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6903732/