From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5735 invoked by alias); 26 Mar 2003 20:16:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 5720 invoked by uid 71); 26 Mar 2003 20:16:00 -0000 Date: Wed, 26 Mar 2003 20:36:00 -0000 Message-ID: <20030326201600.5713.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Glen Nakamura Subject: Re: c/10226: unsigned short promotion with bitwise inversion Reply-To: Glen Nakamura X-SW-Source: 2003-03/txt/msg01832.txt.bz2 List-Id: The following reply was made to PR c/10226; it has been noted by GNATS. From: Glen Nakamura 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