[Bug c/31166] Integer hex constant does not follow promoting rules
roberto dot gordo at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Mar 14 08:53:00 GMT 2007
------- Comment #5 from roberto dot gordo at gmail dot com 2007-03-14 08:52 -------
> unsigned is never promoted, it always stays unsigned.
Sorry to insist, but I'm still not convinced. Please, see these examples,
compiled with -std=c99.
{
unsigned u;
int i;
u = 1; /* this is an unsigned */
i = -u; /* this is an unsigned turned into a negative int */
printf("%d\n", i); /* It will print -1 */
}
Another example.
{
long long ll;
ll = -2147483648;
printf("%lld\n", ll); /* It will print -2147483648 */
}
2147483648 is the same constant as 0x80000000. Acording to your comments, this
is an unsigned, because it does not fit on an int, and it should remain as
unsigned. But it is not. There is not overflow in printf, because I print as
long long.
This is just the same example, because 2147483648 == 0x80000000
{
long long ll;
ll = -0x80000000;
printf("%lld\n", ll); /* It will print 2147483648 */
}
It is the same constant, represented on hex. Just the same number. I'm reading
the ISO C standard right now, and I can't find any explanation for an hex
constant to have such different semantics. If there it is and I've missed it, I
would appreciate to be pointed to the section of the standard which explains
this behavior, please.
--
roberto dot gordo at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31166
More information about the Gcc-bugs
mailing list