c/6607: Inconsisitency using right shift operator (signed vs. unsigned shift)

wheisler@inflow.com wheisler@inflow.com
Wed May 8 10:16:00 GMT 2002


>Number:         6607
>Category:       c
>Synopsis:       Inconsisitency using right shift operator (signed vs. unsigned shift)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 08 10:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Bill Heisler
>Release:        gcc 2.96 20000731
>Organization:
>Environment:
RH 7.1 Intel Glibc 2.2.3-16 gcc 2.96
>Description:
When using a right shift operator that can be calculated at compile time, the operator performs an unsigned shift (prepends zeros).  If the shift is parameterized, and is calculated at run time, a signed shift is performed (prepends high order bit).
>How-To-Repeat:
#include <stdio.h>

int main (int argc, char ** argv) {
   unsigned int i = 0xffffffff >> 32;
   unsigned int j = 0xffffffff;

   j = j >> 32;

   printf("i -- %x\nj -- %x\n", i, j);
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list