* decimal constant so large?
@ 2005-05-28 17:50 a.biardi
2005-05-31 13:15 ` Glynn Clements
0 siblings, 1 reply; 3+ messages in thread
From: a.biardi @ 2005-05-28 17:50 UTC (permalink / raw)
To: linux-c-programming
Hi everybody,
Can anyone tell me why the constant -2147483648, according to what g++ reports
as a warning for the code below, is considered to be "so large that it is
unsigned"?
How can it be unsigned when it starts with '-'?
I am compiling on an x86, and the constant seems to be a perfectly good 32 bit
signed value to me. Where am I wrong?
I've tried it with three different compilers, and they all behave in the same
funny way: Borland C++ compiler 5.7, as well as g++ 3.2.3 report a warning,
Intel compiler 8.1 says nothing.
==============================================================================
#include <iostream>
using namespace std;
int main() {
cout << (int)-2147483648 << endl; // ok
cout << -2147483648 << endl; // prints 2147483648 instead
}
==============================================================================
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: decimal constant so large?
2005-05-28 17:50 decimal constant so large? a.biardi
@ 2005-05-31 13:15 ` Glynn Clements
2005-05-31 23:15 ` Training Darren Sessions
0 siblings, 1 reply; 3+ messages in thread
From: Glynn Clements @ 2005-05-31 13:15 UTC (permalink / raw)
To: a.biardi; +Cc: linux-c-programming
a.biardi@tiscali.it wrote:
> Can anyone tell me why the constant -2147483648,
-2147483648 isn't a constant, it's an expression consisting of the
negation operator "-" applied to the decimal constant "2147483648".
The decimal constant 2147483648 is too large to fit into a signed
32-bit integer, so it is treated as unsigned.
If you want the most negative signed 32-bit integer, you have to write
it as (-2147483647 - 1).
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Training
2005-05-31 13:15 ` Glynn Clements
@ 2005-05-31 23:15 ` Darren Sessions
0 siblings, 0 replies; 3+ messages in thread
From: Darren Sessions @ 2005-05-31 23:15 UTC (permalink / raw)
To: linux-c-programming
I am looking for a training establishment in the South East (United
States) that offers beginners to advanced training in C with a bang
for the buck.
Anyone have any suggestions?
Thanks,
- Darren
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-05-31 23:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-28 17:50 decimal constant so large? a.biardi
2005-05-31 13:15 ` Glynn Clements
2005-05-31 23:15 ` Training Darren Sessions
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).