Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many bytes is unsigned long long?

Tags:

c++

How many bytes is unsigned long long? Is it the same as unsigned long long int ?

like image 828
Dushant Avatar asked Apr 29 '11 19:04

Dushant


People also ask

Is unsigned long always 32-bit?

The answer is definitively YES.


2 Answers

Executive summary: it's 64 bits, or larger.

unsigned long long is the same as unsigned long long int. Its size is platform-dependent, but guaranteed by the C standard (ISO C99) to be at least 64 bits. There was no long long in C89, but apparently even MSVC supports it, so it's quite portable.

In the current C++ standard (issued in 2003), there is no long long, though many compilers support it as an extension. The upcoming C++0x standard will support it and its size will be the same as in C, so at least 64 bits.

You can get the exact size, in bytes (8 bits on typical platforms) with the expression sizeof(unsigned long long). If you want exactly 64 bits, use uint64_t, which is defined in the header <stdint.h> along with a bunch of related types (available in C99, C++11 and some current C++ compilers).

like image 84
Fred Foo Avatar answered Oct 14 '22 17:10

Fred Foo


The beauty of C++, like C, is that the sized of these things are implementation-defined, so there's no correct answer without your specifying the compiler you're using. Are those two the same? Yes. "long long" is a synonym for "long long int", for any compiler that will accept both.

like image 35
Ernest Friedman-Hill Avatar answered Oct 14 '22 17:10

Ernest Friedman-Hill