This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
shifting
- From: "Marko Mlinar" <markom at opencores dot org>
- To: <gcc at gcc dot gnu dot org>
- Date: Thu, 4 Jul 2002 08:25:01 +0200
- Subject: shifting
Hello!
About some time I noticed gcc has strange "feature" with shifting.
Considering we have following program:
int main ()
{
volatile int a = 20;
volatile int b = 20;
const int x = 0xdeaddead;
const int c = 40;
printf ("%08x %08x\n", (x >> a) >> b, x >> c);
return 0;
}
when compining without optimizations we get:
$ gcc s.c -o s && ./s
ffffffff ffdeadde
and with optimizations:
$ gcc s.c -o s -O2 && ./s
s.c: In function `main':
s.c:8: warning: right shift count >= width of type
ffffffff ffffffff
The first result is quite scary. It may also cause serious problems with
different architectures
e.g. 32/64 bit architectures.
I cannot think of an example, but I have it somewhere back in my mind, it
was possible to produce warning,
but still do an errorneous output with -O2 or -O option.
If this issue is known about or it was already closed due to performance
considerations, please let me know.
best regards,
Marko