c - #define 变量的范围是什么?

标签 c scope c-preprocessor

我试图在同一个项目的另一个 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/

相关文章:

c - 如何在 C 中打印定义的字符串宏?

c - 将数字读入数组并在 C 中反向打印

c - static - 仅用于限制范围?

c - 在文件名中添加数字

c++宏将标记识别为参数

给定类型列表的 C++ 专用模板类

c - sendto() 崩溃,错误代码为 "Success"

c - 访问 C 中的结构 - 函数

c - 使用 calloc 将内存分配给 Struct 变量时出现段错误

c++ - 错误 : ‘screen’ was not declared in this scope