From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26572 invoked by alias); 26 Mar 2003 22:16:01 -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 26542 invoked by uid 71); 26 Mar 2003 22:16:00 -0000 Date: Wed, 26 Mar 2003 22:26:00 -0000 Message-ID: <20030326221600.26541.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/msg01848.txt.bz2 List-Id: The following reply was made to PR c/10226; it has been noted by GNATS. From: Glen Nakamura To: Michael Marks Cc: Falk Hueffner , gcc-gnats@gcc.gnu.org Subject: Re: c/10226: unsigned short promotion with bitwise inversion Date: Wed, 26 Mar 2003 12:13:33 -1000 On Wed, Mar 26, 2003 at 01:50:29PM -0800, Michael Marks wrote: > Either is far clearer than the original. > I like the second one better. On second thought, my suggestions won't work for the other comparisons: e.g. <= >= < > != I'm starting to see why it's worded the way it is... > Just one other comment, are both promoted, and are both unsigned after the > promotion. > I thought they are promoted to int. As per you earlier... > > 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. I think it is promoted to int, but that really doesn't matter since: if ((unsigned int) B == ~((unsigned int) A)) would still be false. The problem is widening an unsigned type and then doing a ~ operation, forces the high bits to 1. In contrast, the other unsigned operand is just widened so the high bits are guaranteed 0. Comparison of these two operands can give unexpected results, which is what the warning is trying to illustrate. - glen