How to #define the lowest negative number?

Technical Note 60149

Architectures:

ARM

Component:

compiler

Updated:

11/6/2015 12:38 PM

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.

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.