ARM Technical Support Knowledge Articles

Why do I get a compiler error when using the maximum negative number for a given type in an expression?

Applies to: DS-5, RealView Development Suite (RVDS)


If you define the maximum negative limit for a given signed type using a #define or as part of an constant expression, you will get a compiler warning similar to:

Warning:  #1134-D: literal treated as "long long"

Consider the example below: 

#define LONG_MIN (-2147483648)
long foo = LONG_MIN;

The compiler is interpreting the defined value LONG_MIN as a constant term (2147483648) and a separate negation operator. In order for the expression type checking to pass, the constant term on the right must be representable as the destination type (long).  Here, the constant term in the expression cannot be represented as a signed integer type (maximum positive long is 2147483647) hence resulting in a compiler warning.

The workaround is to either represent the maximum negative in its unsigned form or break the constant into multiple terms.

#define LONG_MIN 0x80000000
#define LONG_MIN (-2147483647-1)

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential