Constant is too large for long long

Technical Note 87534

Architectures:

All

Component:

compiler

Updated:

2015/11/6 12:28

Introduction

I get the message:

Warning[Pe1297]: constant is too large for long long; given unsigned long long type (nonstandard)

.. when using the decimal constant 2147483648.

Possible solutions

  • Use suffix (e.g., 2147483648UL)
  • Use octal or hexadecimal representation instead (e.g., 0x80000000)
  • Combine constants that are not too large, e.g., use LONG_MIN defined as
  • #define LONG_MIN (-2147483647-1)

Background

The standard says the type of a decimal constant without suffix shall be the first that matches in the following list:

int, long int, long long int

The constant 2147483648 (= 0x8000 0000) does not fit in a long long int.

The compiler handles this by using unsigned long long int for the constant, and gives an appropriate warning.

Note

Type casts, e.g.,

/*...*/ (unsigned long long) 2147483648; /*...*/

are not applied until after the constant has a type. See also Technical Note 60149.

 

All product names are trademarks or registered trademarks of their respective owners.

很抱歉,该页面尚未翻译成中文。

如果您有任何问题,请联系我们的中国团队

We do no longer support Internet Explorer. To get the best experience of iar.com, we recommend upgrading to a modern browser such as Chrome or Edge.