Possible Duplicate:
Why are C++ int and long types both 4 bytes?
In C/C++, what is the difference between:
u_int64 myNum;
and:
unsigned long myNum;
As far as I can tell, both ate just unsigned integers, with 64bits of memory.
Possible Duplicate:
Why are C++ int and long types both 4 bytes?
In C/C++, what is the difference between:
u_int64 myNum;
and:
unsigned long myNum;
As far as I can tell, both ate just unsigned integers, with 64bits of memory.
unsigned long
does not have to be 64 bits, whereas uint64_t
does. There is a kind of hierarchy of integer types where each type has to be at least large as the preceding type: signed char
, short
, int
, long
, long long
, and similarly for their unsigned counterparts. There are some anchor points, stating that char
is one byte (a byte does not have to be 8 bits, as far as I can recall short
is at least 2 bytes 16 bits. In C++11, long long is at least 64 bits. But none of these types is exactly a given number of bits.
See fixed width integer types for more information (thanks to @chris for the link).
The C language itself doesn't specify how big an int
is
long
only has to be at least as long as int
long long
only has to be at least as long as long
also u_int64_t
is a c99 type, and wouldn't be available in ANSI c89.
also among 64 bit architectures that are differences LP64 indicates long
's and pointers are 64 bit, LLP64 means that long long
's and pointers are 64 bit.
unsigned long
is dependent on the machine like every int
in C/C++. Many library especially libraries that allow for two machines to interact will type def most int
like numbers to make sure both are the same size. u_int64
is basically type def to an unsigned integer of 64 bits, to allow for use on any machine. In theory unsigned long
could be 128, 64, 256 or pretty much any size.