public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* rshift problem
@ 2008-05-18 18:25 John Kacur
2008-05-18 18:28 ` Andrew Pinski
0 siblings, 1 reply; 2+ messages in thread
From: John Kacur @ 2008-05-18 18:25 UTC (permalink / raw)
To: gcc-bugs
cat rshift.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned j = ~0 >> 8;
unsigned i = ~0;
i >>= 8;
printf("i = %x\n", i);
printf("j = %x\n", j);
exit(0);
}
gcc -o rshift rshift.c -Wall -g
jkacur@athena:~/b1systems/ckurs> ./rshift
i = ffffff
j = ffffffff
jkacur@athena:~/b1systems/ckurs> gcc --version
gcc (GCC) 4.2.1 (SUSE Linux)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Am I just doing something wrong? Why aren't i and j equal?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: rshift problem
2008-05-18 18:25 rshift problem John Kacur
@ 2008-05-18 18:28 ` Andrew Pinski
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Pinski @ 2008-05-18 18:28 UTC (permalink / raw)
To: John Kacur; +Cc: gcc-bugs
On Sun, May 18, 2008 at 11:24 AM, John Kacur <jkacur@gmail.com> wrote:
> int main(void)
> {
> unsigned j = ~0 >> 8;
The above is signed right shift which will keep the sign bit and replicate it.
> unsigned i = ~0;
> i >>= 8;
While this is an unsigned right shift.
-- Pinski
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-05-18 18:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-18 18:25 rshift problem John Kacur
2008-05-18 18:28 ` Andrew Pinski
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).