macos 在 64 位 CPU 上使用 C++ 编写的 Mac OS X 上,是否有 64 位类型?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2383520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:48:28  来源:igfitidea点击:

On Mac OS X in C++ on a 64-bit CPU, is there a type that is 64 bits?

c++macos64-bit

提问by anon

I can't use "long long"; what should I be using?

我不能用“long long”;我应该使用什么?

回答by Jonathan Leffler

Assuming Snow Leopard (Mac OS X 10.6.2 - Intel), then 'long' is 64-bits with the default compiler.

假设 Snow Leopard(Mac OS X 10.6.2 - Intel),则“long”是 64 位,使用默认编译器。

Specify 'g++ -m64' and it will likely be 64-bits on earlier versions too.

指定 'g++ -m64' 并且在早期版本上也可能是 64 位。

 1 = sizeof(char)
 1 = sizeof(unsigned char)
 2 = sizeof(short)
 2 = sizeof(unsigned short)
 4 = sizeof(int)
 4 = sizeof(unsigned int)
 8 = sizeof(long)
 8 = sizeof(unsigned long)
 4 = sizeof(float)
 8 = sizeof(double)
16 = sizeof(long double)
 8 = sizeof(size_t)
 8 = sizeof(ptrdiff_t)
 8 = sizeof(time_t)
 8 = sizeof(void *)
 8 = sizeof(char *)
 8 = sizeof(short *)
 8 = sizeof(int *)
 8 = sizeof(long *)
 8 = sizeof(float *)
 8 = sizeof(double *)
 8 = sizeof(int (*)(void))
 8 = sizeof(double (*)(void))
 8 = sizeof(char *(*)(void))

Tested with:

测试:

i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646) (dot 1)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling with GCC 4.7.1 on Mac OS X 10.7.5 with option -std=c99, the output from the program is more extensive. Thanks to apalopohapafor pointing out the oversight that long longetc were missing from the original.

使用选项 在 Mac OS X 10.7.5 上使用 GCC 4.7.1 进行编译,-std=c99程序的输出更广泛。感谢apalopohapa指出long long原文中缺少的疏忽。

 1 = sizeof(char)
 1 = sizeof(unsigned char)
 2 = sizeof(short)
 2 = sizeof(unsigned short)
 4 = sizeof(int)
 4 = sizeof(unsigned int)
 8 = sizeof(long)
 8 = sizeof(unsigned long)
 4 = sizeof(float)
 8 = sizeof(double)
16 = sizeof(long double)
 8 = sizeof(size_t)
 8 = sizeof(ptrdiff_t)
 8 = sizeof(time_t)
 8 = sizeof(long long)
 8 = sizeof(unsigned long long)
 8 = sizeof(uintmax_t)
 1 = sizeof(int8_t)
 2 = sizeof(int16_t)
 4 = sizeof(int32_t)
 8 = sizeof(int64_t)
 1 = sizeof(int_least8_t)
 2 = sizeof(int_least16_t)
 4 = sizeof(int_least32_t)
 8 = sizeof(int_least64_t)
 1 = sizeof(int_fast8_t)
 2 = sizeof(int_fast16_t)
 4 = sizeof(int_fast32_t)
 8 = sizeof(int_fast64_t)
 8 = sizeof(uintptr_t)
 8 = sizeof(void *)
 8 = sizeof(char *)
 8 = sizeof(short *)
 8 = sizeof(int *)
 8 = sizeof(long *)
 8 = sizeof(float *)
 8 = sizeof(double *)
 8 = sizeof(int (*)(void))
 8 = sizeof(double (*)(void))
 8 = sizeof(char *(*)(void))
 1 = sizeof(struct { char a; })
 2 = sizeof(struct { short a; })
 4 = sizeof(struct { int a; })
 8 = sizeof(struct { long a; })
 4 = sizeof(struct { float a; })
 8 = sizeof(struct { double a; })
16 = sizeof(struct { char a; double b; })
16 = sizeof(struct { short a; double b; })
16 = sizeof(struct { long a; double b; })
 4 = sizeof(struct { char a; char b; short c; })
16 = sizeof(struct { char a; char b; long c; })
 4 = sizeof(struct { short a; short b; })
 6 = sizeof(struct { char a[3]; char b[3]; })
 8 = sizeof(struct { char a[3]; char b[3]; short c; })
16 = sizeof(struct { long double a; })
32 = sizeof(struct { char a; long double b; })
16 = sizeof(struct { char a; long long b; })
16 = sizeof(struct { char a; uintmax_t b; })

回答by F'x

Include <stdint.h>or <inttypes.h>(the later is found on some more compilers, but both are provided by the Apple compiler), and use uint64_tand int64_t. They are 64-bit on both 32-bit and 64-bit targets.

包括<stdint.h>or <inttypes.h>(后者在更多编译器上找到,但两者都由 Apple 编译器提供),并使用uint64_tand int64_t。它们在 32 位和 64 位目标上都是 64 位的。