views:

87

answers:

2

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

+2  A: 

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

Scharrels
Technically it doesn't, but most compilers support it (and C's `stdint.h` header, which defines `int64_t` and `uint64_t`) as an extension.
Mike Seymour
Standardized only in C++0x, not the current C++03.
Klaim
+4  A: 

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.

Michael Borgwardt
What do you mean with "the Java standard mandates big endian"? Java primitive types are abstracted from the actual low-level storage of their content, so there's no way to tell which endianess is used by a specific Java VM.
jarnbjo
@jarnbjo: Ok, to be completely exact: the java standard mandates that primitives behave as if they were big endian wherever it matters, such as inside class files, or when they're serialized.
Michael Borgwardt
The Java standard does not mandate big endianness. In Java you don't have direct access to memory (no pointers) so there is no need to mandate any endianness.
Jesper
@Michael: What you are saying is that Java class files and serialized objects are using a big endian format (which is correct). That has however nothing to do with how Java VMs are storing and managing primitive times internally at run time.
jarnbjo