c - 将外部变量导入本地时, `#include` 和 `extern` 有什么区别?

标签 c

在使用errno时,我曾经读到过这样的话

It is important to include errno.h rather than providing your own extern int errno, since errno is implemented in a thread-safe manner that is more than just a simple global int.

线程安全方式如何影响#includeextern之间的区别?

最佳答案

重要的不是 extern 还是 #include

errno 在 header 中定义为

int*    _errno(void);
#define errno       (*_errno())

每个线程在其自己的地址空间中都有自己的错误号

关于c - 将外部变量导入本地时, `#include` 和 `extern` 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9956768/

相关文章:

c - 当 super 结构引用非常量时如何使用 const C 结构?

c - 如何从字符串中获取数值(将其转换为 int)?

c - c中指向指针赋值的指针

c - 使用 Visual Studio 2013 时 .c 文件中的语法错误

c++ 等效于 calloc 并为数组变量声明空间

c - 强制 gcc 使用系统调用

c - 包含在资源文件 Visual Studio 中不起作用

c++ - sprintf 未定义行为

C 结构,指向结构的 union 指针

c - 有没有办法使用 08 和 09 并消除八进制常量错误中的无效数字 "8"?