Discussion:
What's the meaning of this warning: this decimal constant is unsigned only in ISO C90
(too old to reply)
Nan Li
2008-12-13 22:40:47 UTC
Permalink
Hello,

Can any one help me understand the meaning of this warning: this
decimal constant is unsigned only in ISO C90 ? I think -2147483648 is
the min number for 32 bit signed integer.

#include <stdint.h>

static const int32_t value = -2147483648;

warning: this decimal constant is unsigned only in ISO C90

gcc version 4.0.2 20051125


Thanks !
Jack Klein
2008-12-13 23:40:30 UTC
Permalink
Post by Nan Li
Hello,
Can any one help me understand the meaning of this warning: this
decimal constant is unsigned only in ISO C90 ? I think -2147483648 is
the min number for 32 bit signed integer.
#include <stdint.h>
static const int32_t value = -2147483648;
warning: this decimal constant is unsigned only in ISO C90
gcc version 4.0.2 20051125
Thanks !
The expression "-2147483648" consists of two parts, an integer literal
and a unary minus operator. There are no negative integer literals.

The type of a decimal integer literal in C90 is the first of the
following in which its value will fit: int, signed long, unsigned
long. I am assuming that your long it 32 bits, and 2147483648 is too
large to fit into a signed long, so it is evaluated as an unsigned
long value. Then the unary minus operator is applied to it. Finally,
that result is used to initialize the int32_t.

It would be much better to use the macro INT32_MIN, from <stdint.h>,
in the initialization.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Juha Nieminen
2008-12-14 13:42:27 UTC
Permalink
Post by Jack Klein
It would be much better to use the macro INT32_MIN, from <stdint.h>,
in the initialization.
For what it's worth, at least here INT32_MIN is defined as:
(-2147483647-1)

The reason is probably what you explained.

Loading...