Is the type "long long" always 64 bits?
I'm trying to implement George Marsaglia's Complementary Multiply-With-Carry algorithm in C. It seems to work great under Win7 64 bit and Linux 32 bit, but seems to behave strangely under Win 7 32 bit. The random number it returns is 32 bit, but there's a temporary value used internally that's supposed to be 64 bits, and it's declared:
unsigned long long t;
I susp开发者_如何学Goect this might be the cause of the misbehaviour, so my question is:
Is the type "long long" 64 bits? Is it supported in 32 bit Windows?
If your compiler has stdint.h
I would suggest using uint64_t
instead.
The type long long
is guaranteed to be at least 64 bits (although the guarantee is formally in the form of the range of values it must be able to represent).
The following is in §5.2.4.2.1 of the C99 standard (link to draft):
— maximum value for an object of type
unsigned long long int
ULLONG_MAX 18446744073709551615 // 2**64 − 1
精彩评论