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]

egcs 1.1.2 problem; shift on integers gives unexpected sign extension.



Hi!

Machine:          Alpha DS20 with 2G RAM and 2x500 Mz CPU's
Operating system: SuSE: 6.3 Linux, kernel:  SuSE 2.2.13-SMP

I am trying to get MySQL to work reliable on Alpha Linux:


****************************
egcs 1.1.2 problem;  shift on integers gives unexpected sign extension.
****************************

Just save the following program as shift-bug.c and follow the instructions in
the comment:

---------
/*
** shift on integers gives unexpected sign extension.
** This 'may' be right, but it's not predictable and SHOULD at least give
** a warning on 64 bit architectures!

How about adding a warning when doing shift on unsigned values
on 64 bit machines?

Test:

(/my/bugs) gcc -v
Reading specs from /usr/lib/gcc-lib/alpha-unknown-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
(/my/bugs) gcc -Wall shift-bug.c -o shift-bug
(/my/bugs) shift-bug
1 << 31 = -2147483648 = 0x ffffffff80000000
1U << 31 = 2147483648 = 0x 80000000

**
*/

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
  unsigned long a=0;
  int b=31;

  a= 1 << b;
  printf("1 << 31 = %ld = 0x %lx\n",a,a);
  a= 1U << b;
  printf("1U << 31 = %ld = 0x %lx\n",a,a);
  return(0);
}

------------

Regards,
Monty
MySQL Moderator

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