2010-03-04 69 views
5

我不能用「long long」;我應該使用什麼?在64位CPU上的C++中的Mac OS X上,是否有64位的類型?

+2

爲什麼你不能使用'long long'?你的編譯器不支持它嗎? – 2010-03-04 23:40:14

+0

你使用什麼編譯器? – Cameron 2010-03-04 23:43:19

+3

達爾文/ MacOSX是否支持固定大小的整型typedefs,如int64_t?如果是這樣,我會使用這些。有關詳細信息,請參閱http://www.opengroup.org/onlinepubs/000095399/basedefs/stdint.h.html。 – Void 2010-03-04 23:53:47

回答

12

假設Snow Leopard(Mac OS X 10.6.2 - Intel),那麼'長'是64位的默認編譯器。

指定'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)) 

與測試:

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.

在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; }) 
+4

此外,如果您包含,則可以使用int64_t和uint64_t,它們被鍵入到適當的類型類型中,並使其明確指出您正在使用的內容。 – bobDevil 2010-03-04 23:55:55

+1

int64_t *在al *實際上是在 2010-03-05 08:40:26

+3

依靠剛剛發佈的表是不好的建議。如果你想要64位,使用'int64_t'。這是標準的原因。 – asveikau 2010-03-05 10:08:45

3

包括<stdint.h><inttypes.h>(後來是在一些編譯器中,但兩者都是由蘋果公司提供的編譯器),並使用uint64_tint64_t。它們在32位和64位目標上都是64位的。

相關問題