c/10226: unsigned short promotion with bitwise inversion

Falk Hueffner falk.hueffner@student.uni-tuebingen.de
Wed Mar 26 18:26:00 GMT 2003


The following reply was made to PR c/10226; it has been noted by GNATS.

From: Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
To: mmarks@internetmachines.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c/10226: unsigned short promotion with bitwise inversion
Date: 26 Mar 2003 19:23:10 +0100

 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



More information about the Gcc-prs mailing list