c++ - 为什么函数名 f4 有内部链接,而不是 C 语言链接?

标签 c++ language-lawyer linkage

[dcl.link]/4中的第五个例子陈述如下:

extern "C" {
    static void f4(); // the name of the function f4 has internal linkage (not C language linkage)
                      // and the function’s type has C language linkage.
}

这是为什么?为什么函数名f4有内部链接,而不是C语言链接?

P.S.:我是从语言律师的角度问这个问题的。也就是说,如何从标准中的规范性段落中推导出上面的注释声明?

最佳答案

在同一部分,强调我的:

In a linkage-specification, the specified language linkage applies to the function types of all function declarators, function names with external linkage, [...]

但是,f4 被声明为static,这意味着该名称根据[basic.link]/3 具有内部链接。 :

A name having namespace scope has internal linkage if it is the name of:

  • a variable, function or function template that is explicitly declared static; or, [...]

因此,C 链接不适用。

关于c++ - 为什么函数名 f4 有内部链接,而不是 C 语言链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45358729/

相关文章:

c# - C++/CLI->C# 错误 C2526 : C linkage function cannot return C++ class

c++ - 内联函数链接错误 C++

c++ - 为什么 const std::vector 将 const 应用于包含的对象?

C++ + 运算符的这种用法叫什么?目的是什么?

javascript - Gecko 的 Javascript 解释器引擎语义是什么?

c++ - 为什么允许将整型、枚举和成员指针类型reinterpret_cast 为自身?

c++ - 是std::memomove在同一对象之间始终是安全的

c++ - 带参数的累积正态分布函数的反函数

c++ - 如何使用 Int 65H 输出字符串?

c++ - 类有外部链接吗?