public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/53369] Integral promotion with ~ operator - Different behavior for signed and unsigned char. Date: Wed, 16 May 2012 01:39:00 -0000 [thread overview] Message-ID: <bug-53369-4-NjoEiAxUbH@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-53369-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53369 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-05-16 00:11:53 UTC --- signed char a = 1 << 7; unsigned char b = 1 << 7; printf("%hd %hu\n", ~a, ~b); let's see ~a is really ~(int)a. Likewise ~b is really ~(int)b. #define printf __builtin_printf int main(void) { signed char a = 1 << 7; unsigned char b = 1 << 7; printf("%x %x\n", ~a, ~b); } --- CUT ---- 7f ffffff7f This is the correct behavior. As (int)(unsigned char)a does a zero extend as the unsigned char fits directly in an int. Think of this way. The value from unsigned char and signed char are unchanged when promoted into int. So with the first one you get -128 and the second case you get 128. and then you take the ~ and you get 127 and (~(1<<7)) .
next prev parent reply other threads:[~2012-05-16 0:12 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-05-16 0:04 [Bug c/53369] New: " rahulnitk2004 at gmail dot com 2012-05-16 0:05 ` [Bug c/53369] " rahulnitk2004 at gmail dot com 2012-05-16 0:12 ` rahulnitk2004 at gmail dot com 2012-05-16 1:39 ` pinskia at gcc dot gnu.org [this message] 2012-05-16 9:12 ` rahulnitk2004 at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-53369-4-NjoEiAxUbH@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).