Cpp: eclipse does not recognize long long type

I have a place where in my code the following line: long long maxCPUTime = 4294967296;

(the largest number of the long type may be 4294967296 -1, so I used long long)

The problem is that when compiling I get the following error:

error: integer constant is too large for 'long' type 

As if the eclipses did not recognize that I wrote "long long", and he believes that I wrote "long".

(I am using linux os)

Does anyone know why I am getting this error?

+6
source share
2 answers

Add LL to it:

 long long maxCPUTime = 4294967296LL; 

This should solve the problem. ( LL is preferred over LL because it is easier to distinguish.)

long long was not officially added to the standard until C99 / C ++ 11.

Generally, whole literals will be of the smallest type to hold it. But before C99 / C ++ 11, long long did not exist in the standard. (but most compilers had this extension). Therefore (with some compilers) integer literals larger than long do not get the type long long .

+6
source

The problem is that your constant (4294967296) does not fit into int and unsigned int (in fact, it also does not fit into long - what the compiler says) and does not automatically rise to long long , thus, an error. You must add the suffix LL (or LL , although the latter may be confused by shortsighted people like me for 11 ) to make it long long :

 long long maxCPUTime = 4294967296LL; 
+5
source

Source: https://habr.com/ru/post/906913/


All Articles