- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
来自C++17 Standard Draft § 3.5.6
:
The name of a function declared in block scope and the name of a variable declared by a block scope extern declaration have linkage. If there is a visible declaration of an entity with linkage having the same name and type, ignoring entities declared outside the innermost enclosing namespace scope, the block scope declaration declares that same entity and receives the linkage of the previous declaration. If there is more than one such matching entity, the program is ill-formed. Otherwise, if no matching entity is found, the block scope entity receives external linkage
此外,标准中还提供了一个示例:
static void f();
static int i = 0; // #1
void g() {
extern void f(); // internal linkage
int i; // #2 i has no linkage
{
extern void f(); // internal linkage
extern int i; // #3 external linkage
}
}
第三个函数声明extern void f()
是否接收:
external
链接(由于前面的 extern void f()
声明)internal
链接(因为上面 block 作用域中 f()
的第二个声明从 f()
的声明接收内部链接在 ::
全局命名空间中)编辑
main.cpp
#include <iostream>
extern void g();
void f() { std::cout << "main f() called" << std::endl; }
int main(){
g();
return 0;
}
测试.cpp:
#include <iostream>
static void f() { std::cout << " test f() called" << std::endl; }
void g() {
extern void f();
{
extern void f();
f();
}
}
g()
在 main.cpp
的 main()
函数中被调用。
使用 gcc 5.4.0
g++ -std=c++14 -Wall main.cpp test.cpp
打印:
main f() called
因此,gcc 显然将 g()
中的 f()
调用与 external
链接(调用在main.cpp
文件)。标准示例中的注释是错误的(#3
的函数声明没有内部链接)或者它是来自 gcc
的编译器错误。
最佳答案
我不明白你的困惑。最里面的封闭命名空间范围是 global namespace 的范围;第一个和第二个声明在类型和名称上匹配,因此外部 block 范围声明仅继承全局声明的链接(由于 static
说明符,它是内部的)。第二个 block 作用域声明与第一个关联;你明白了。
关于c++ - 根据 C++17 标准草案在 block 作用域中声明为 `extern` 的函数的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41978949/
我正在尝试将draft-js的EditorContent保存到数据库,然后再次读取并重新创建EditorContent对象。但是 EditorContent.getPlainText() 会去除富文本
我已经按照 v3 规范草案创建了一个 JSON 模式。架构如下所示: { "$schema": "http://json-schema.org/draft-03/schema#", "addition
我正在尝试用 java 实现一个 websockets 服务器,但我无法理解 google chrome 实现的 websocket 协议(protocol)的版本。在 this Chromium 团
我正在使用 CXF 和 Jackson 构建 RESTful 服务。我需要根据 json 模式验证 JSON 数据(草案 4)。我想我应该在反序列化之前验证它。 我已经浏览过https://githu
N3290 ISO 标准草案 §3.4.1/12 中的一点: During the lookup of a name used in the constant-expression of an enu
有onChange事件,但当插入符移动或按下导航(箭头等)按钮时也会触发。 我想检测内容是否已更改。基本上我只需要在第一次更改发生时检测一次。 “比较内容”的愚蠢方式在这里可能有效,但这是一种反模式,
Github 不久前发布了 draft PR。 我有一个普通的 PR,我想将其更改为 PR 草案。我怎样才能做到这一点? 最佳答案 更新 - 现已推出 - 2020 年 1 月 转换默认 → 草稿 现
我正在 iPhone 上构建客户端以使用 WebSockets draft hixie 76 协议(protocol)连接到一台服务器。 我已经试过了 UnittWebSocketClient ,但他
ISO C++ 草案 (n3290) 中的一点: 3.4.2/3 Argument Dependant Name Lookup: Let X be the lookup set produced by
随着 (X)HTML5 规范接近标准化,我更喜欢在适用于勺子式自动工具的任何地方使用微数据,其次是 RDFa,因为微数据的个人感觉与简洁一样受限,其次是使用 XSLT 为我的工作用户提供服务的 mic
我得到了一些由具有大量属性的 REST API 生成的 JSON 文件。 我已经为此 API 创建了 Swagger 2.0 定义,并且需要为其提供相应的响应架构。 主要问题:这个 JSON 文件有很
在将 Draft-js-mention-plugin 纳入我的应用程序时,我遇到了问题。请看一下: "Warning: React does not recognize the isFocused p
我在这里 (SO) 看到太多关于 OAuth 以及如何使用 OAuth 协议(protocol)连接到 Facebook Graph API 或 Twitter API 的问题。 我发现了 JOAut
我是一名优秀的程序员,十分优秀!