[Bug fortran/20473] New: false arithmetic with short integers

ralph dot doering at web dot de gcc-bugzilla@gcc.gnu.org
Mon Mar 14 18:49:00 GMT 2005

The Operation 2*i with short integers (KIND=3, KIND=6) give incorrect values if
the result exeeds the definded range for this types. The program example
compiled with  

g77 test.f

give the following results:
integer*1:      100+100=-56,         2*100=200
integer*2:      20000+20000=-25536,  2*20000=40000

The second one of each line ist mathematical correct, but outside the valid
range of the data type.

Test System was a Redhat Linux 4 Enterprise on Dual Opteron
gcc-Version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)

Also seen with gcc 3.3.1 on Suse Linux 9.1 on Pentium M, and with
cygwin gcc 3.3.3 on Xeon System.

      program short_int_test

      implicit none
      integer*1  i1
      integer*2  i2

      print*, i1+i1, 2*i1
      print*, i2+i2, 2*i2


           Summary: false arithmetic  with short integers
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ralph dot doering at web dot de
                CC: gcc-bugs at gcc dot gnu dot org


More information about the Gcc-bugs mailing list