How to #define the lowest negative number?

Technical Note 60149

Arkitekturer:

ARM

Komponent:

compiler

Uppdaterad:

2015-11-06 12:38

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.

Det här innehållet finns tyvärr inte på svenska.

Vår webbplats finns främst på vårt koncernspråk engelska, förutom det innehåll för investerare som vi är lagstadgade att kommunicera på svenska. Vi rekommenderar att du besöker vår globala webbplats på engelska för att få en bättre upplevelse.

Vi stöder inte längre Internet Explorer. För att få bästa möjliga upplevelse av iar.com rekommenderar vi att du uppgraderar till en modern webbläsare som Chrome eller Edge.