This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Possible bug with range checking
- From: Arjen Markus <arjen dot markus895 at gmail dot com>
- To: fortran at gcc dot gnu dot org
- Date: Thu, 27 Jan 2011 12:05:43 +0100
- Subject: Possible bug with range checking
Hello,
in the PLplot project we are facing a small problem with gfortran. One
of the components in PLplot
uses a set of constants that are easiest set via the hexadecimal
format as in the program below:
program boz
integer, parameter :: PL_FCI_MARK = z'80000000'
write(*,*) PL_FCI_MARK
end program
The value that should result is -2147483648, the largest negative
integer that can be stored in 32-bits.
However, if I compile this program with gfortran version 4.5 or 4.6, I get:
boz.f90:5.35:
integer, parameter :: PL_FCI_MARK = z'80000000'
1
Error: Arithmetic overflow converting INTEGER(8) to INTEGER(4) at (1).
This check can be disabled with the option -fno-range-check
As the integer is a perfectly acceptable integer, I think this is an error.
A slight modification to the program shows the compiler's check is not
even consistent if it is NOT an error:
program boz
integer, parameter :: PL_FCI_MARK = -2147483647
write(*,*) PL_FCI_MARK-1
end program
is accepted, but if you subtract 2 instead of 1, the compiler
complains about an integer overflow.
Regards,
Arjen