This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/35213] New: 1 << -1 inconsistent across platforms


I personally would never dare to write any code that could result in an
expression like:
  1 << -1

Unfortunately I found some code that uses it.

Eventually I learned that the following code behaves differently on i386 and
ppc64:

  #include <stdio.h>
  int main(int argc, char *argv[])
  {
    int shifter = 0;
    unsigned int target = 0;
    target |= (1 << (shifter -1));
    printf("%x\n", target);
  }

On i386, it prints 80000000.
On ppc64, it prints 0.


Should gcc be changed to be consistent across platforms?
It might help those that platforms that are being used less frequently.


-- 
           Summary: 1 << -1 inconsistent across platforms
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kengert at redhat dot com
 GCC build triplet: ppc64-yellowdog-linux
  GCC host triplet: ppc64-yellowdog-linux
GCC target triplet: ppc64-yellowdog-linux


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]