가장 낮은 음수를 "#defined" 으로 정의

기술노트 60149

아키텍처:

ARM

컴포넌트:

compiler

업데이트:

2018-02-28 오전 1:46

Introduction

This Technical Note answers the question: 'How to #define the lowest negative number, without getting a compiler warning?'

It applies to the IAR C/C++ Compiler for ARM and some other IAR C/C++ Compilers.

Problem

When making a #define with the lowest possible value the IAR C/C++ Compiler issues a warning and changes sign on the value.

#define MIN_VALUE (-2147483648L)
signed long lValue;
lValue = (MIN_VALUE + 1);

Example (32 bit integer)

The string of...
-2147483648L

...is interpreted by the Compiler as two parts, first the...

-

..is interpreted as the "minus operator", and secondly...

2147483648L

...is interpreted as a constant. And that constant is larger than LONG_MAX.

Solution

#define MIN_VALUE (-2147483647L - 1)

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

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