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

Nan Li

Usenet Archive
Joined
Sep 14, 2005
Messages
47
Reaction score
0
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

Usenet Archive
Joined
Aug 21, 2000
Messages
3,261
Reaction score
0
On Sat, 13 Dec 2008 14:40:47 -0800 (PST), Nan Li
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

...

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.
 

Juha Nieminen

Usenet Archive
Joined
Jun 7, 2006
Messages
3,204
Reaction score
0
Jack said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top