[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

What's the meaning of this warning: this decimal constant is unsigned only in ISO C90

absurd

12/13/2008 10:41:00 PM

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 !
2 Answers

Jack Klein

12/13/2008 11:41:00 PM

0

On Sat, 13 Dec 2008 14:40:47 -0800 (PST), Nan Li <nan.li.g@gmail.com>
wrote in comp.lang.c++:

> 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-Tech...
FAQs for
comp.lang.c http://...
comp.lang.c++ http://www.parashift.com/c++...
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-...

Juha Nieminen

12/14/2008 1:42:00 PM

0

Jack Klein wrote:
> 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.