#定义__CLIBNS ::的std ::在C标准的头文件,如stdio.h中 [英] #define __CLIBNS ::std:: in C standard header files such as stdio.h

查看:1920
本文介绍了#定义__CLIBNS ::的std ::在C标准的头文件,如stdio.h中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了标准的头文件 stdio.h中 ARM编译器的定义如下:

I see the following definition in the standard header file stdio.h of the ARM compiler:

#undef __CLIBNS
#ifdef __cplusplus
  namespace std {
  #define __CLIBNS ::std::
    extern "C" {
#else /* ndef __cplusplus */
  #define __CLIBNS
#endif /* ndef __cplusplus */

这样做有什么意义呢?如果我有口code,它使用 _CLIBNS 在GCC?
是否有类似的宏,我应该使用?

What is the significance of this? What if I have to port the code which uses _CLIBNS in gcc? Are there similar macros I should use?

推荐答案

简短的回答:你可能不希望使用的程序armcc的副本< stdio.h中> 与海湾合作委员会 - 使用gcc(或newlib的)

Short answer: you probably don't want to use armcc's copy of <stdio.h> with gcc -- use gcc's (or newlib's).

&LT; stdio.h中&GT; 允许使用 __ CLIBNS ,因为它是实现的一部分;你,作为用户,都没有(除非执行的文件告诉你,否则)。在C语言中有没有这样的命名空间 __ CLIBNS 定义不了了之。在C ++中大部分的内容&LT; stdio.h中&GT; 是在全局命名空间 STD - 但不是preprocessor宏(的#define S),因为他们不关心命名空间(宏是邪恶的,但历史的必然)。因此,&LT;文件stdio.h&gt;在它的宏定义,以确保它有宏定义参照使用 __ CLIBNS STD 命名空间中的东西,当你使用C ++。

<stdio.h> is allowed to use __CLIBNS because it is part of the implementation; you, as the user, are not (unless the implementation's documentation tells you otherwise). In C there are no namespaces so __CLIBNS is defined to nothing. In C++ most of the contents of <stdio.h> are in the global namespace std -- but not preprocessor macros (#defines) because they don't care about namespaces (macros are evil but historically necessary). So <stdio.h> uses __CLIBNS in it's macro definitions to make sure that the macros it has to define refer to the things in the std namespace when you are using C++.

这篇关于#定义__CLIBNS ::的std ::在C标准的头文件,如stdio.h中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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