我正在阅读有关链接(外部、内部和无)的 C 引用资料,并遇到以下内容:
If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined.
我想知道这种未定义的行为是如何发生的。根据我的阅读,一个变量只能有一个存储类。所以它不能同时声明为 static
和 extern
。
那么在什么情况下一个变量可以同时具有内联和外联呢?
最佳答案
在这段代码中:
extern int x;
static int x;
第一个声明说 x
有外部链接,第二个声明说它有内部链接。
关于c - 在 C 中同时创建内部和外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63757005/