的sizeof(长)的64位C ++sizeof

由网友(小痞子°)分享简介:我已经下载的MinGW-64,所以我现在可以编译64位程序的Windows 7,采用G ++ 4.7.0(实验)。但是下面一行:COUT<<的sizeof(长)<< <<的sizeof(无效*)<< ENDL;打印 4月8日,不是 8 8 。该文档G ++ 4.6.0说:...

我已经下载的MinGW-64,所以我现在可以编译64位程序的Windows 7,采用G ++ 4.7.0(实验)。但是下面一行:

  COUT<<的sizeof(长)<< <<的sizeof(无效*)<< ENDL;
 

打印 4月8日,不是 8 8 。该文档G ++ 4.6.0说:

  

64位环境套诠释到32位,long和指针为64位。

有谁知道为什么的sizeof(长)不是8?

编辑补充:我的问题的根源是,G ++ 4.7.0的64位Windows(还)没有GNU编译器集的正式组成部分。而它的第64位版本,32位,所以文件根本不适用。事实上,如果你去相关网页,为全面进入 IA-32 / X86-64 由这样的:

  

...

解决方案

由于它并没有如此。 C ++标准只要求它(如果没有记错)至少32位宽,并且至少一样大的 INT

MSVC(和Windows使用的ABI)定义为32位宽,和MinGW跟风,因为很好,编译器,当它同意了很多有用与主机操作系统

c语言中sizeof的用法

I have downloaded MinGW-64, so I can now compile 64-bit programs for Windows 7, using g++ 4.7.0 (experimental). But the following line:

cout << sizeof(long) << " " << sizeof(void*) << endl ;

prints 4 8, not 8 8. The documentation for g++ 4.6.0 says:

The 64-bit environment sets int to 32 bits and long and pointer to 64 bits

Does anybody know why sizeof(long) is not 8?

Edited to add: The source of my confusion was that g++ 4.7.0 for 64-bit Windows is not (yet) an official part of the GNU Compiler Collection. And it's the first 64-bit version with a 32-bit long, so the documentation simply doesn't apply to it. Indeed, if you go to the relevant web page, the full entry for IA-32/x86-64 consists of this:

...

解决方案

Because it doesn't have to be. The C++ standard only requires that it is (if memory serves) at least 32 bits wide, and at least as big as int.

MSVC (and the ABI used by Windows) defines long to be 32 bits wide, and MingW follows suit because well, the compiler is a lot more useful when it agrees with the host OS

阅读全文

相关推荐

最新文章