我们可以在没有 static 关键字的情况下声明具有内部链接的文件范围标识符吗?

标签 c

C 标准的第 6.11.2 节说明了在 future 版本中可能会被弃用的功能之一:

Declaring an identifier with internal linkage at file scope without the static storage-class specifier is an obsolescent feature.



在没有静态存储类说明符的情况下,如何声明文件范围标识符以具有内部链接?

最佳答案

在 C++ 标准中有一个针对此问题的具体示例。
在 [dcl.stc] 中:

static int b; // b has internal linkage
extern int b; // b still has internal linkage
因此,在第二行中,b 被声明为具有内部链接的文件范围标识符,没有关键字 static。
这个例子也适用于 C,如 C11:6.2.2 所说:

For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration. If no prior declaration is visible, or if the prior declaration specifies no linkage, then the identifier has external linkage.


see this question for more detail

关于我们可以在没有 static 关键字的情况下声明具有内部链接的文件范围标识符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61529890/

相关文章:

c - 声明指向 __far 指针的指针的正确方法是什么?

c - 字符串比较中的十六进制文字问题

C:删除句子中的空格;抛出异常:写访问冲突

你可以 bool 值小于比较 C 中的 2 个 void * 值吗?

C 读取文件并将数字保存在数组中

c - 在句子中存储指向单词的指针

创建一个新的瘦进程、 fork 还是线程?

c - 子进程在 C 中终止后,父进程未完成

c - SDL_GetKeyName 的倒数

c - 了解特定代码示例中的指针