http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47821

           Summary: BUG: warning: left shift count >= width of type
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: nfav...@uwo.ca


Created attachment 23409
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23409
Example c program for UltraSPARC producing incorrect results with left shift

While developing a 64bit program for the UltraSPARC,
I was warned shifting 56 times left was >= width of type
See attachment code.
Since you may not be able to run it,
here is the output: 

sizeof 'k'  is 4
sizeof 'kk' is 8
sizeof 'B'  is 1
B = 2c (hex)
2c000000            <-----This is not correct!

The last line should be:
2c00000000000000    <-----This is correct (32 bits more)


The issue here is this:
kk is a long int (64 bits)
and compiling produces a warning:
(at line 39): warning: left shift count >= width of type

Line 39 is:

    kk = (B << 56);    // place B in bit position 63..56 of 64 bits

This warning is incorrect.
-AND-
The compiled code is incorrect.

-NF

Reply via email to