- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
所以这是我一直想知道但一直不太确定的事情。所以这完全是出于好奇,而不是真正的问题。
据我了解,当您执行 #include <cstdlib>
之类的操作时一切(当然宏除外)都在 std::
中声明命名空间。我见过的每个实现都是通过执行以下操作来实现的:
#include <stdlib.h>
namespace std {
using ::abort;
// etc....
}
这当然具有全局命名空间和 std
中的效果。 .这种行为是否得到保证?或者是否有可能实现可以将这些东西放在 std
中?但不在全局命名空间中?我能想到的唯一方法是让你的 libstdc++ 实现每个 c 函数本身,将它们放在 std
中。直接而不是只包含现有的 libc header (因为没有从命名空间中删除某些内容的机制)。这当然是付出了很多努力,却几乎没有任何好处。
我的问题的本质是,以下程序是否严格符合并保证工作?
#include <cstdio>
int main() {
::printf("hello world\n");
}
编辑:我找到的最接近的是这个(17.4.1.2p4):
Except as noted in clauses 18 through 27, the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in ISO/IEC 9899:1990 Programming Languages C (Clause 7), or ISO/IEC:1990 Programming Languages—C AMENDMENT 1: C Integrity, (Clause 7), as appropriate, as if by inclusion. In the C + + Standard Library, however, the declarations and definitions (except for names which are defined as macros in C) are within namespace scope (3.3.5) of the namespace std.
说实话,我可以用任何一种方式解释。 “每个 header cname 的内容应与相应 header name.h 的内容相同,如 ISO/IEC 9899:1990 Programming Languages C 中所指定的那样”告诉我它们可能在全局命名空间中是必需的,但是“在但是,C++ 标准库的声明和定义(名称除外)在 C 中定义为宏)在命名空间 std 的命名空间范围内(3.3.5)。”表示它们在 std 中(但没有指定它们所在的任何其他范围)。
最佳答案
下面是 MSVC 团队 (http://blogs.msdn.com/vcblog/archive/2008/08/28/the-mallocator.aspx#8904359) 的 Stephan T. Lavavej 对情况的一个很好的概要(与标准所说的相比有些相关性):
>
also,<cstddef>
,<cstdlib>
, andstd::size_t
etc should be used!I used to be very careful about that. C++98 had a splendid dream wherein
<cfoo>
would declare everything within namespace std, and<foo.h>
would include<cfoo>
and then drag everything into the global namespace with using-declarations. (This is D.5 [depr.c.headers].)This was ignored by lots of implementers (some of which had very little control over the C Standard Library headers). So, C++0x has been changed to match reality. As of the N2723 Working Paper, http://open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2723.pdf , now
<cfoo>
is guaranteed to declare everything within namespace std, and may or may not declare things within the global namespace.<foo.h>
is the opposite: it is guaranteed to declare everything within the global namespace, and may or may not declare things within namespace std.In reality and in C++0x, including
<cfoo>
is no safeguard against everything getting declared in the global namespace anyways. That's why I'm ceasing to bother with<cfoo>
.This was Library Issue 456, http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#456 .
(C++0x still deprecates the headers from the C Standard Library, which is hilarious.)
我自己从不喜欢 <cfoo>
header ,发现我一直使用 <foo.h>
。现在我觉得我可以不再为我在这方面缺乏 C++“纯度”而焦虑了。
关于c++ - <c____> 头文件中声明的 C 函数是否保证在全局命名空间和 std 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2587445/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
有没有办法保证您的系统托盘图标被删除? 添加系统托盘图标: Shell_NotifyIcon(NIM_ADD, &m_tnd); 删除系统托盘图标: Shell_NotifyIcon(NIM_DELE
是否保证(-x) % m,其中x和m在c++中为正standard (c++0x) 为负数,等于 -(x % m)? 我知道它在我知道的所有机器上都是正确的。 最佳答案 除了Luchian的回答,这是
可能还有其他方法可以作为示例,但这不是我要问的重点。 我正在这样做: (future (clojure.java.shell/sh "sleep" "3" :dir "/tmp")) 启动对Shell
可以使用 XREAD(或者可能是另一个命令)以原子方式检测数据是否写入 Redis 流? 进一步来说: 假设您在一个进程中将一些数据添加到 Redis 流中,并看到数据已通过某个自动生成的 key 成
Kotlin 协程是否提供任何“发生之前”保证? 例如,在这种情况下,写入 mutableVar 和随后在(可能)其他线程上读取之间是否存在“发生之前”保证: suspend fun doSometh
我正在开发一个跟踪行程的应用程序。在搜索了这件事之后,我得出结论,实现这一点(持续跟踪用户的位置)的最好方法是使用前台服务。在某些情况下工作得很好,但在其他一些情况下(即使关闭 DOZE),我得到一些
我正在使用 ORM (sqlalchemy) 从 PG 数据库中获取数据。我想避免在我手工编写的 SQL 语句中指定所有表列名称*。 到目前为止,我的假设是返回的列按照用于创建数据库表的 DDL 语句
在 setState 的文档中这样说: setState() does not immediately mutate this.state but creates a pending state tr
我有一个与不同硬件接口(interface)的简单应用程序。对于每个硬件,我针对一个独特的监视器函数生成了一个 pthread_t,总共有 6 个线程:1 个管理线程和 5 个工作线程。 每个线程都有
目前,我有 private ThreadLocal shortDateFormat = new ThreadLocal() { @Override protected DateFormat i
我有一个使用 SolrCloud 将文档写入 Solr 的 Java 作业。输入数据被转换为不同实体的映射,然后将每个实体写入与其实体类型对应的 Solr 集合。 我的代码如下: public voi
我们使用嵌入式设备通过串行到以太网转换器将数据包从串行端口发送到服务器。我们使用的一家制造商 Moxa 将始终以与构建它们相同的方式发送数据包。意思是,如果我们构建一个大小为 255 的数据包,它将始
我是从 C++ 转到 Java 的。在 C++ 世界中,我们关注异常安全,并注意到变元器可以在变元器本身或其委托(delegate)的方法抛出异常时提供不同的保证(最小、强、不抛出)。实现具有强异常保
我想将来自 SAAJ 的 SOAPConnectionFactory 和 MessageFactory 类与多个线程一起使用,但事实证明我不能假设它们是线程安全的。一些相关的帖子: javax.xml
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
关于正确性,我找不到以下代码片段没有设计缺陷的证据/反证据。 template class MyDirtyPool { public: template std::size_t ad
对于这个问题,我找到了不同的答案,我知道一定有一个确定的答案。 C 中四种主要数据类型的最小分配内存大小是多少? int , double , float , 和 char是我在想什么。做 signe
我正在使用 Kafka Producer,我的应用程序将具有相同键的各个 ProducerRecords 发送到单个分区中,然后这些 ProducerRecords 在发送到代理之前进行批处理(使用
您好,我是服务器端编程 (java) 的新手,正在阅读 SendRedirect 与 Forward 之间的区别。来自 Post-redirect-get pattern它解释说这将阻止通过点击刷新按
我是一名优秀的程序员,十分优秀!