c - 在 C 中同时创建内部和外部链接

标签 c language-lawyer extern internal-link

我正在阅读有关链接(外部、内部和无)的 C 引用资料,并遇到以下内容:

If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined.

我想知道这种未定义的行为是如何发生的。根据我的阅读,一个变量只能有一个存储类。所以它不能同时声明为 staticextern

那么在什么情况下一个变量可以同时具有内联和外联呢?

最佳答案

在这段代码中:

extern int x;
static int x;

第一个声明说 x 有外部链接,第二个声明说它有内部链接。

关于c - 在 C 中同时创建内部和外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63757005/

相关文章:

c - 头文件 : type defaults to 'int' 中的结构定义

我们可以在头文件中使用带有 typedef 数据类型的 extern 关键字吗?

c - 为什么 int_fast16_t 在 64 位系统上是 64 位?

c++ - CMake 行军硬件

c - 为什么Ruby FFI在有头文件的情况下还需要调用attach_function?

c++ - 为什么在这里创建对 prvalue 的左值引用是合法的?

C 中灵活数据类型项的调用堆栈 API

c++ - 数组元素是不完整的对象吗?

c++ - 引用基类的 constexpr 构造函数因编译器而异

c - 使用链接器命令将 C 中的数组分配到特定位置