long long 에 비해 너무 큰 상수

기술노트 87534

아키텍처:

All

컴포넌트:

compiler

업데이트:

2018-02-28 오전 1:45

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.

죄송하지만, 당사 사이트에서는 Internet Explorer를 지원하지 않습니다.보다 편안한 사이트를 위해 Chrome, Edge, Firefox 등과 같은 최신 브라우저를 사용해 주시길 부탁드립니다.