How to initialize an unsigned long long type?
21,812
Solution 1
Try suffixing your literal value with ULL
Solution 2
First, be sure your compiler supports the long long type. Second, add a "ULL" suffix to the number.
Solution 3
Q: How to initialize an unsigned long long type?
A: With an unsigned long long constant!
(Add suffix ULL
to the constant.)
Author by
Admin
Updated on April 19, 2020Comments
-
Admin about 4 years
I'm trying to initialize an
unsigned long long int
type. But the compiler is throwing an error"error: integer constant is too large for "long" type ".
The initialization is shown below :
unsigned long long temp = 1298307964911120440;
Can anybody please let me know what the problem is and suggest a solution for the same.
-
GManNickG about 14 yearsJust to clarify,
unsigned long long
has to be at least 64-bits. -
Michael Aaron Safyan about 14 years@GMan, unsigned long long doesn't have to be anything until C++0x officially becomes ISO C++ 2011. It would be far more portable to use uint64_t from <inttypes.h>, assuming both the header and type exist.
-
GManNickG about 14 years@Michael: I thought it was implicit that we were talking about the future, since Jerry says "be sure your compiler supports the long long type". Anyway, I agree if we wanted to force a number to be exactly 64-bit, that would be better, but if we just want a large-number-guaranteed-to-be-at-least-64-bits,
unsigned long long
would be better. -
Steve Jessop about 14 years@GMan: or
uint_least64_t
. cstdint is going to be in C++0x too. -
GManNickG about 14 years@Steve: Oh yes, I forgot about those. I change my choice to that instead. :]