ANSI C函数的命名空间,ISO C ++ [英] ANSI C functions namespace in ISO C++

查看:126
本文介绍了ANSI C函数的命名空间,ISO C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的小程序:

 的#include< cstdio>诠释主(){
    的printf(%d个\\ N,1);
    的std :: printf的(%d个\\ N,2);
    返回0;
}


  1. 什么是C ++标准说的默认的导入C库函数到全局命名空间的?你可以点我到相关的C ++标准节?

  2. 这是什么原因ANSI C函数在 STD 在首位的命名空间,因为它们在默认情况下导入到全局命名空间?


解决方案

7.4.1.2/4:


  

除了18至27条款中所指出的,每个标题的内容 CNAME 应是相同相应的头的 name.h ,如ISO指定/ IEC 9899:1990编程语言C(第7条),或ISO / IEC:1990编程语言-C修订1:C完整性,(第7条),在适当时,如果包容性。在C ++标准库,但是,声明和定义(除了被定义为C宏名称)的名称空间的命名空间范围(3.3.5)中的 STD


D.5 / 2:


  

每一个C头,每个具有形式 name.h 的名字,表现为如果相应的<$ C放置在标准库空间每一个名字$ C> CNAME 头也放在空间std的命名空间范围之内,后面跟着一个明确的using声明(7.3.3)。


在实践中, name.h 包括并于全局 CNAME 在全局命名空间的名字和 STD 命名空间(即其他各地超过标准规定的方式)。

Consider the following small program:

#include <cstdio>

int main() {
    printf("%d\n", 1);
    std::printf("%d\n", 2);
    return 0;
}

  1. What does C++ standard say about importing C library functions into global namespace by default? Can you point me to the relevant C++ standard section?
  2. What is the reason ANSI C functions are in std namespace in the first place, since they are by default imported into global namespace?

解决方案

7.4.1.2/4:

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.

D.5/2:

Every C header, each of which has a name of the form name.h, behaves as if each name placed in the Standard library namespace by the corresponding cname header is also placed within the namespace scope of the namespace std and is followed by an explicit using-declaration (7.3.3).

In practice, however, name.h includes the names in the global namespace and cname in both the global and std namespace (i.e. the other way around than the standard specifies).

这篇关于ANSI C函数的命名空间,ISO C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆