Small error in range check?
Anton Shterenlikht
mexas@bris.ac.uk
Thu Dec 12 14:35:00 GMT 2013
>Date: Thu, 12 Dec 2013 15:20:40 +0100
>Subject: Small error in range check?
>From: Arjen Markus <arjen.markus895@gmail.com>
>To: Fortran List <fortran@gcc.gnu.org>
>
>Hello,
>
>I ran into a slight problem regarding one-byte integers. The program
>below illustrates it:
>
>! chkbyte.f90 --
>! Check the range for an integer of one byte
>! This ought to be from -128 to +127
>!
>program chkbyte
> implicit none
>
> integer, parameter :: byte = 1
> integer(kind=byte) :: var
>
> var = -128_byte
>
> write(*,*) var
>end program chkbyte
>
>The gfortran compiler (I tried with 4.5, 4.7 and 4.8) does not like
>the value of -128 for such integers.
>As far as I know the range for such integers is -128 to 127 and if I
>turn off the range checking, the variable is indeed set to -128.
neither does 4.9:
gfortran49 z.f90
z.f90:7.19:
var = -128_byte
1
Error: Integer too big for its kind at (1). This check can be disabled with the option -fno-range-check
Neither should it, I think.
I think -HUGE() is always guaranteed to work,
however, -HUGE()-1 might or might not work,
depending on the platform. Am I wrong?
Anton
More information about the Fortran
mailing list