From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7896 invoked by alias); 26 Mar 2003 19:36:11 -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 7722 invoked by uid 71); 26 Mar 2003 19:36:02 -0000 Date: Wed, 26 Mar 2003 19:56:00 -0000 Message-ID: <20030326193602.7721.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Michael Marks Subject: RE: c/10226: unsigned short promotion with bitwise inversion Reply-To: Michael Marks X-SW-Source: 2003-03/txt/msg01829.txt.bz2 List-Id: The following reply was made to PR c/10226; it has been noted by GNATS. From: Michael Marks To: 'Falk Hueffner' Cc: gcc-gnats@gcc.gnu.org Subject: RE: c/10226: unsigned short promotion with bitwise inversion Date: Wed, 26 Mar 2003 11:27:06 -0800 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C2F3CD.AFA9C7E0 Content-Type: text/plain; charset="iso-8859-1" Actually I understood that the warning was tied to that error. I would suggest: warning : ~ operator caused promotion of unsigned short to int Interestingly: Sun CC passes and Microsoft Fails without warning. Michael. -----Original Message----- From: Falk Hueffner [mailto:falk.hueffner@student.uni-tuebingen.de] Sent: Wednesday, March 26, 2003 10:23 AM To: mmarks@internetmachines.com Cc: gcc-gnats@gcc.gnu.org Subject: Re: c/10226: unsigned short promotion with bitwise inversion mmarks@internetmachines.com writes: > When two unsigned shorts (16 bit) variables are compared with one being inverted the comparison will fail. > The following code should pass, while it does generate a warning it > should instead just work. > > unsigned short A = 0xDEAD; > unsigned short B; > B = ~A; > if ( B == ~A) { > printf("Pass\n"); > } > else { > printf("Fail\n"); > } Apparently, you didn't understand the warning. The C standard mandates that "~A" will promote A to int first. So gcc is behaving correctly here. Any suggestions on how the wording of the message could be improved to be clearer? -- Falk ------_=_NextPart_001_01C2F3CD.AFA9C7E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable RE: c/10226: unsigned short promotion with bitwise = inversion

Actually I understood that the warning was tied to = that error.

I would suggest:
warning : ~ operator caused promotion of unsigned = short to int

Interestingly: Sun CC passes and Microsoft Fails = without warning.

Michael.

-----Original Message-----
From: Falk Hueffner [mailto:falk.hueff= ner@student.uni-tuebingen.de]
Sent: Wednesday, March 26, 2003 10:23 AM
To: mmarks@internetmachines.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c/10226: unsigned short promotion with = bitwise inversion


mmarks@internetmachines.com writes:

> When two unsigned shorts (16 bit) variables are = compared with one being inverted the comparison will fail.
> The following code should pass, while it does = generate a warning it
> should instead just work.
>
>    unsigned short A =3D = 0xDEAD;
>    unsigned short B;
>    B =3D ~A;
>    if ( B =3D=3D ~A) {
>       = printf("Pass\n");
>    }
>    else {
>       = printf("Fail\n");
>    }

Apparently, you didn't understand the warning. The C = standard mandates
that "~A" will promote A to int first. So = gcc is behaving correctly
here. Any suggestions on how the wording of the = message could be
improved to be clearer?

--
        Falk

------_=_NextPart_001_01C2F3CD.AFA9C7E0--