Handling “integer constant is too large for “long” type” error

This kind of compiler error happens when an integer is too large to be stored in a single 32-bit register. A common situation is when a user is compiling 64-bit optimized code on a 32-bit machine. Therefore, one register of the 64-bit machine has size of two registers of a 32-bit machine. So, in order to compile integer that long, the user has to inform the processor that the integer has to be stored on two 32-bit registers (all together, 64 bits).

Commonly, the type of the integer can be changed to “long long int”

Example:

long long int var = 10000000000;

Another option is specifying the type using the suffix LL.

int var = 10000000000LL;

There are other suffixes available. For instance, if the variable is unsigned (cannot contain negative values,but can store values of larger magnitude than the signed type), you can safely use the suffix LLU.

Example:

int var = 10000000000LLU;

2 Responses to "Handling “integer constant is too large for “long” type” error"

  • Nelson says:
  • Gorav says:
Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word