什么是之间-std =在GCC的差异GNU ++ 0x中和-std = C ++ 0x中,哪一个应该被使用? [英] What's the difference in GCC between -std=gnu++0x and -std=c++0x and which one should be used?

查看:3193
本文介绍了什么是之间-std =在GCC的差异GNU ++ 0x中和-std = C ++ 0x中,哪一个应该被使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦与< stdint.h> 在使用 -std =的C ++ 0x 在GCC 4.4.3(Android版):

I'm having troubles with <stdint.h> when using -std=c++0x in GCC 4.4.3 (for Android):

// using -std=c++0x
#include <stdint.h>
uint64_t value;  // error: 'uint64_t' does not name a type

不过,使用 -std = GNU ++ 0x中

// using -std=gnu++0x
#include <stdint.h>
uint64_t value;  // OK

&LT; stdint.h&GT; 用C ++ 0x中不兼容

Is <stdint.h> incompatible with C++0x?

推荐答案

据我所知道的,我觉得这可以说是实现的bug(或实际上,因为的C ++ 0x没有发布,而不是一个错误本身的,但一个不完整的实施即将到来的标准的当前状态)。

So far as I can tell, I think this could be argued an implementation bug (or actually, since C++0x isn't published, not a bug per se but an incomplete implementation of the current state of the upcoming standard).

这里的原因,指的是n3225为预期的行为 -std =的C ++ 0x

Here's why, referring to n3225 for the expected behavior of -std=c++0x:

D.7说:

每次C头,每一个都具有一   形式name.h的名称,行为就好像   每个名字放在标准   通过相应的库命名空间   CNAME头被置于内   全局命名空间范围

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 placed within the global namespace scope

确定,到目前为止那么容易。这是什么&LT; cstdint&GT; 地方标准库命名空间

OK, so far so easy. What does <cstdint> place in the standard library namespace?

18.4.1:

typedef unsigned integer type uint64_t; // optional

如何选购? 18.4.1 / 2:

How optional? 18.4.1/2:

头去网络网元的所有功能,   类型,和宏一样在7.18   C标准

The header defines all functions, types, and macros the same as 7.18 in the C standard

讨厌鬼。什么是C标准说什么?取出n1256,7.18.1.1/3:

Drat. What does the C standard say? Taking out n1256, 7.18.1.1/3:

这些类型是可选的。然而,   如果一个实现提供整数   类型,宽度为8,16,32,或64   位,无填充比特,和(对于   符号类型)具有   二的补重新presentation,它   应取消科幻NE相应的typedef   名称

These types are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a two's complement representation, it shall define the corresponding typedef names

但挂在,想必在Android与 -std =的C ++ 0x GCC的确实的提供了一个64位无符号的类型,没有填充位:无符号长长。因此,&LT; cstdint&GT; 需要提供的std :: uint64_t中,因此 stdint.h 需要提供 uint64_t中全局命名空间。

But hang on, surely on Android with -std=c++0x GCC does provide a 64 bit unsigned type with no padding bits: unsigned long long. So <cstdint> is required to provide std::uint64_t and hence stdint.h is required to provide uint64_t in the global namespace.

继续,有人告诉我,为什么我错了:-)一种可能性是的C ++ 0x指的是ISO / IEC 9899:1999编程语言 - C,而不指定版本。难道真的是因为(一)7.18.1.1/3中添加了热带气旋之一,也是(B)的C ++ 0x打算引用原标准为1999年,而不是修正,因为呢?我怀疑其中任一的话,但我没有这方面的原有C99检查(一),我甚至不知道如何检查(B)。

Go on, someone tell me why I'm wrong :-) One possibility is that C++0x refers to "ISO/IEC 9899:1999 Programming languages — C" without specifying a version. Can it really be that (a) 7.18.1.1/3 was added in one of the TCs, and also (b) C++0x intends to reference the original standard as of 1999, not the amendments since then? I doubt either of these is the case, but I don't have the original C99 on hand to check (a) and I'm not even sure how to check (b).

编辑:哦,至于哪一个应该使用 -std =的C ++ 0x 是不是一个真正的严格标准兼容模式还没有,因为有ISN T A严格的标准呢。即使有一个标准,GCC 4.4.3肯定不是最终实现它。所以,我认为没有迫切需要使用它,如果 -std = GNU ++ 0x中实际的更完整的的,至少在这方面你的组合的gcc版本和平台。

oh, as for which one should be used -std=c++0x isn't really a strict standards-compliant mode yet, since there isn't a strict standard yet. And even if there was a standard, gcc 4.4.3 certainly isn't a finished implementation of it. So I see no great need to use it if -std=gnu++0x is actually more complete, at least in this respect for your combination of gcc version and platform.

不过, GNU ++ 0x中将使其他GNU扩展,你可能不希望您的code使用。如果你的目标写便携式的C ++ 0x,那么最终你会想切换到 -std =的C ++ 0x 。但我不认为GCC 4.4或任何其他的C ++ 0x的实施正在进行中的是完整的还不够它是实际从(草案)标准写code,如果你可以说采用了直板脸我编程的C ++ 0x,而且只有2011!。所以,我想说,无论使用哪一部作品,并理解您现在使用哪一个,你可能会切换到 -std = C ++ 11 最终反正。

However, gnu++0x will enable other GNU extensions, that you might not want your code to use. If you're aiming to write portable C++0x, then eventually you'd want to switch to -std=c++0x. But I don't think GCC 4.4 or any other C++0x implementation-in-progress is complete enough yet for it to be practical to write code from the (draft) standard, such that you could say with a straight face "I'm programming C++0x, and it's only 2011!". So I'd say, use whichever one works, and understand that whichever one you use now, you'll probably be switching to -std=c++11 eventually anyway.

这篇关于什么是之间-std =在GCC的差异GNU ++ 0x中和-std = C ++ 0x中,哪一个应该被使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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