c/10226: unsigned short promotion with bitwise inversion
Glen Nakamura
glen@imodulo.com
Wed Mar 26 20:36:00 GMT 2003
The following reply was made to PR c/10226; it has been noted by GNATS.
From: Glen Nakamura <glen@imodulo.com>
To: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
mmarks@internetmachines.com
Cc:
Subject: Re: c/10226: unsigned short promotion with bitwise inversion
Date: Wed, 26 Mar 2003 10:06:02 -1000
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10226
> unsigned short A = 0xDEAD;
> unsigned short B;
> B = ~A;
> if ( B == ~A) {
> printf("Pass\n");
> }
> else {
> printf("Fail\n");
> }
I'll leave the final decision to the language lawyers, but I don't think
this is a bug in GCC. The ~ operator is subject to integer promotion,
so with the implicit conversions the expression becomes:
if ((int) B == ~((int) A))
which is indeed false in the example above.
In fact, I see the following warning when compiling with -Wall (GCC 3.3):
warning: comparison of promoted ~unsigned with unsigned
Perhaps "if (B == (unsigned short) ~A)" will behave as you expect.
- glen
More information about the Gcc-prs
mailing list