cpp: eclipse doesn't recognize 'long long' type

1.2k views Asked by At

I have some where in my code the next line: long long maxCPUTime=4294967296;

(the largest number long type can be is 4294967296 -1 , so I used long long)

the problem is, when I compile ,I get the next error:

error: integer constant is too large for ‘long’ type

Its as if, eclips doesn't recognize that I wrote 'long long' and it thinks I wrote 'long'.

(I'm using linux os)

anyone knows why I get this error?

2

There are 2 answers

2
Mysticial On

Append LL to it:

long long maxCPUTime = 4294967296LL;

That should solve the problem. (LL is preferred over ll as it's easier to distinguish.)

long long wasn't officially added to the standard until C99/C++11.

Normally, integer literals will have the minimum type to hold it. But prior to C99/C++11, long long didn't "exist" in the standard. (but most compilers had it as an extension) So therefore (under some compilers) integer literals larger than long don't get the long long type.

0
vitaut On

The problem is that your constant (4294967296) doesn't fit into int and unsigned int (actually it doesn't fit into long as well - that's what compiler is saying) and is not automatically promoted to long long, thus the error. You have to add the suffix LL (or ll although the latter may be confused by short-sighted people like me for 11) to make it long long:

long long maxCPUTime = 4294967296LL;