I can't use "long long"; what should I be using?
+5
A:
Assuming Snow Leopard (Mac OS X 10.6.2 - Intel), then 'long' is 64-bits with the default compiler.
Specify 'g++ -m64' and it will likely be 64-bits on earlier versions too.
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.
Jonathan Leffler
2010-03-04 23:45:53
Additionally, if you include <types.h>, you can use int64_t, and uint64_t, which are typedef'd to the appropriate type type, and makes it explicit what you are using.
bobDevil
2010-03-04 23:55:55
int64_t *at al* are actually in <stdint.h>
Paul R
2010-03-05 08:40:26
Relying on the table you just posted is bad advice. If you want 64 bits, use `int64_t`. It's standard for a reason.
asveikau
2010-03-05 10:08:45
+3
A:
Include or (the later is found on some more compilers, but both are provided by the Apple compiler), and use uint64_t
and int64_t
. They are 64-bit on both 32-bit and 64-bit targets.
FX
2010-03-05 10:05:01