Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ variant for Java long?

Is there a C++ variant for the long primitive data-type?
A C++ long is only 4 bytes, while a Java long is 8 bytes.

So: Is there a non-decimal primitive type with a size of 8 bytes in C++?
Maybe with some tricks?

Thanks

like image 908
Martijn Courteaux Avatar asked Jan 25 '26 21:01

Martijn Courteaux


2 Answers

Microsoft Visual C++ defines an __int64 type that's equivalent to Java's long. gcc has int64_t. There's even a long long int type defined in the ISO C99 standard, however according to the standard it's at least 64 bits wide, but could be wider.

But apart from the size, there's also endianness to consider. The Java standard mandates big endian, but with C, endianness is AFAIK always platform-dependant.

like image 134
Michael Borgwardt Avatar answered Jan 27 '26 09:01

Michael Borgwardt


C++ has a long long type, with a length of 64 bits (on most platforms).

like image 41
Scharrels Avatar answered Jan 27 '26 10:01

Scharrels



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!