mingos
mingos

Reputation: 24502

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 suspect 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?

Upvotes: 3

Views: 1840

Answers (2)

caf
caf

Reputation: 239011

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

Upvotes: 5

Trent
Trent

Reputation: 13477

If your compiler has stdint.h I would suggest using uint64_t instead.

Upvotes: 7

Related Questions