I just wanted to know, Why we need to have uint64_t
which is actually a typedef of unsigned long
, when unsigned long is anyway available. Is it only for make the name short or any other reason ?

- 3,930
- 4
- 25
- 55
5 Answers
The reason should be pretty obvious; it's a guarantee that there is 64 bits of precision. There is no such guarantee for unsigned long
.
The fact that on your system it's a typedef
, just means that on your system unsigned long
is 64 bits. That's not true in general, but the typedef
can be varied (by the compiler implementors) to make the guarantee for uint64_t
.

- 391,730
- 64
- 469
- 606
It's not always a typedef for unsigned long
, because unsigned long
is not universally 64 bit wide. For example, on x64 Windows, unsigned long
is 32 bit, only unsigned long long
is 64 bit.
Because uint64_t
means a type of exactly 64 bits, where unsigned long
can be 32 bits or higher.
On a system where unsigned long is 32 bits, it would be used to typedef uint32_t
, and unsigned long long
would be used to typedef uint64_t
.

- 25,460
- 4
- 47
- 87
Yes, it does make it shorter, but that's not the only reason to use it. The main motto of using this typedef
-ed data types is to make a code more robust and portable accross various platforms.
Sometimes, unsigned long
may not be 64 bits, but a definition of uint64_t
will always gurantee 64 bit precision. The typedef of uint64_t
can [ read as : will] be varied accross different platform to have a precision of 64 bits.
Example:
- for systems having
long
as 32 bits,uint64_t
will be typedef tounsigned long long
- for systems having
long
as 64 bits,uint64_t
will be typedef tounsigned long

- 133,132
- 16
- 183
- 261
-
`unsigned long` is already not-64-bit *today*, on x64 Windows for example. – Nov 26 '14 at 09:14
-
Actually `unsigned long` wasn't 64bit for a *long* time... – DevSolar Nov 26 '14 at 09:15
Not only to make it shorter, but also to make it more descriptive.
If you see in code uint64_t
it will be easy to read as unsigned int of 64 bits data type
.

- 921
- 8
- 16