Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why we require uint64_t when unsigned long is available ? [duplicate]

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 ?

like image 388
Chinna Avatar asked Sep 17 '25 23:09

Chinna


2 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.

like image 127
unwind Avatar answered Sep 20 '25 15:09

unwind


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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!