tags:

views:

365

answers:

3

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.

+4  A: 

First, be sure your compiler supports the long long type. Second, add a "ULL" suffix to the number.

Jerry Coffin
Just to clarify, `unsigned long long` has to be at least 64-bits.
GMan
@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.
Michael Aaron Safyan
@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.
GMan
@GMan: or `uint_least64_t`. cstdint is going to be in C++0x too.
Steve Jessop
@Steve: Oh yes, I forgot about those. I change my choice to that instead. :]
GMan
+12  A: 

Try suffixing your literal value with ULL

codaddict
+3  A: 

Q: How to initialize an unsigned long long type?

A: With an unsigned long long constant!

(Add suffix ULL to the constant.)

Didier Trosset