fortrangfortran

Why gfortran could not compile program with 64bits integer without the option -fno-range-check?


I could not compile this simple program without the option -fno-range-check :

program big_int
  use ISO_FORTRAN_ENV

  integer(kind=int64) :: my_int
  print *, huge(my_int)
  my_int = 9223372036854775807
  print *, my_int
end program big_int

The command gfortran my_pgm.f90 raises this error:

Error: Integer too big for its kind at (1). This check can be disabled with the option '-fno-range-check'

gfortran -fno-range-check my_pgm.f90 compiles perfectly. But, I'm a little bored using this option. Is there another option to use ? (gfortran version : GNU Fortran (GCC) 13.2.1 20240316) Thanks for answer.


Solution

  • In fortran, for literals of not default kinds, you must append its kind with an underscore to the literal.

    The 9223372036854775807 is int64 literal and can't fit in default integer kind. you must append "_int64" to it.

    program big_int
      use ISO_FORTRAN_ENV
    
      integer(kind=int64) :: my_int
      print *, huge(my_int)
      my_int = 9223372036854775807_int64
      print *, my_int
    end program big_int