Long integer in Fortran 95 causes `Error: Integer too big for its kind` -
i error message compiling fortran 95 program:
$ gfortran test_select_real_kind.f90 test_select_real_kind.f90:148.23: tinteger_12=12345678911 1 error: integer big kind @ (1). check can disabled option -fno-range-check
the program looks test_select_real_kind.f90:
program test implicit none real :: r r = 4.34 call test_sel_real_kind() call test_sel_int_kind() call test_sel_real_kind_on_int() contains subroutine test_sel_real_kind() implicit none integer, parameter :: long1 = selected_real_kind(p=1) integer, parameter :: long2 = selected_real_kind(p=2) integer, parameter :: long3 = selected_real_kind(p=3) integer, parameter :: long4 = selected_real_kind(p=4) integer, parameter :: long5 = selected_real_kind(p=5) integer, parameter :: long6 = selected_real_kind(p=6) integer, parameter :: long7 = selected_real_kind(p=7) integer, parameter :: long8 = selected_real_kind(p=8) integer, parameter :: long9 = selected_real_kind(p=9) integer, parameter :: long10 = selected_real_kind(p=10) integer, parameter :: long11 = selected_real_kind(p=11) integer, parameter :: long12 = selected_real_kind(p=12) integer(kind=long1) :: tlong1 integer(kind=long2) :: tlong2 integer(kind=long3) :: tlong3 integer(kind=long4) :: tlong4 integer(kind=long5) :: tlong5 integer(kind=long6) :: tlong6 integer(kind=long7) :: tlong7 integer*8 :: tlong8 integer(kind=long9) :: tlong9 integer(kind=long10) :: tlong10 integer(kind=long11) :: tlong11 integer(kind=long12) :: tlong12 write(*,*)' ' write(*,*)'testing integer selected_real_kind values ' write(*,*)' longs1 = ', tlong1,' @ kind =', long1 write(*,*)' longs2 = ', tlong2,' @ kind =', long2 write(*,*)' longs3 = ', tlong3,' @ kind =', long3 write(*,*)' longs4 = ', tlong4,' @ kind =', long4 write(*,*)' longs5 = ', tlong5,' @ kind =', long5 write(*,*)' longs6 = ', tlong6,' @ kind =', long6 write(*,*)' longs7 = ', tlong7,' @ kind =', long7 write(*,*)' longs8 = ', tlong8,' @ kind =', long8 write(*,*)' longs9 = ', tlong9,' @ kind =', long9 write(*,*)' longs10 = ', tlong10,' @ kind =', long10 write(*,*)' longs11 = ', tlong11,' @ kind =', long11 write(*,*)' longs12 = ', tlong12,' @ kind =', long12 write(*,*)' ' end subroutine test_sel_real_kind subroutine test_sel_real_kind_on_int() implicit none integer, parameter :: long1 = selected_real_kind(p=1) integer, parameter :: long2 = selected_real_kind(p=2) integer, parameter :: long3 = selected_real_kind(p=3) integer, parameter :: long4 = selected_real_kind(p=4) integer, parameter :: long5 = selected_real_kind(p=5) integer, parameter :: long6 = selected_real_kind(p=6) integer, parameter :: long7 = selected_real_kind(p=7) integer, parameter :: long8 = selected_real_kind(p=8) integer, parameter :: long9 = selected_real_kind(p=9) integer, parameter :: long10 = selected_real_kind(p=10) integer, parameter :: long11 = selected_real_kind(p=11) integer, parameter :: long12 = selected_real_kind(p=12) real(kind=long1) :: treal_1 real(kind=long2) :: treal_2 real(kind=long3) :: treal_3 real(kind=long4) :: treal_4 real(kind=long5) :: treal_5 real(kind=long6) :: treal_6 real(kind=long7) :: treal_7 real(kind=long8) :: treal_8 real(kind=long9) :: treal_9 real(kind=long10) :: treal_10 real(kind=long11) :: treal_11 real(kind=long12) :: treal_12 !treal_12=12345678911 write(*,*)' ' write(*,*)'testing real selected_real_kind values ' write(*,*)' treal_1 = ', treal_1 write(*,*)' treal_2 = ', treal_2 write(*,*)' treal_3 = ', treal_3 write(*,*)' treal_4 = ', treal_4 write(*,*)' treal_5 = ', treal_5 write(*,*)' treal_6 = ', treal_6 write(*,*)' treal_7 = ', treal_7 write(*,*)' treal_8 = ', treal_8 write(*,*)' treal_9 = ', treal_9 write(*,*)' treal_10 = ', treal_10 write(*,*)' treal_11 = ', treal_11 write(*,*)' treal_12 = ', treal_12 write(*,*)' ' end subroutine test_sel_real_kind_on_int subroutine test_sel_int_kind() implicit none integer, parameter :: long1 = selected_int_kind(1) integer, parameter :: long2 = selected_int_kind(2) integer, parameter :: long3 = selected_int_kind(3) integer, parameter :: long4 = selected_int_kind(4) integer, parameter :: long5 = selected_int_kind(5) integer, parameter :: long6 = selected_int_kind(6) integer, parameter :: long7 = selected_int_kind(7) integer, parameter :: long8 = selected_int_kind(8) integer, parameter :: long9 = selected_int_kind(9) integer, parameter :: long10 = selected_int_kind(10) integer, parameter :: long11 = selected_int_kind(11) integer, parameter :: long12 = selected_int_kind(12) integer(kind=long1) :: tinteger_1 integer(kind=long2) :: tinteger_2 integer(kind=long3) :: tinteger_3 integer(kind=long4) :: tinteger_4 integer(kind=long5) :: tinteger_5 integer(kind=long6) :: tinteger_6 integer(kind=long7) :: tinteger_7 integer(kind=long8) :: tinteger_8 integer(kind=long9) :: tinteger_9 integer(kind=long10) :: tinteger_10 integer(kind=long11) :: tinteger_11 integer(kind=long12) :: tinteger_12 tinteger_12=12345678911 write(*,*)' ' write(*,*)'testing integer selected_int_kind values ' write(*,*)' tinteger_1 = ', tinteger_1,' @ kind =', long1 write(*,*)' tinteger_2 = ', tinteger_2,' @ kind =', long2 write(*,*)' tinteger_3 = ', tinteger_3,' @ kind =', long3 write(*,*)' tinteger_4 = ', tinteger_4,' @ kind =', long4 write(*,*)' tinteger_5 = ', tinteger_5,' @ kind =', long5 write(*,*)' tinteger_6 = ', tinteger_6,' @ kind =', long6 write(*,*)' tinteger_7 = ', tinteger_7,' @ kind =', long7 write(*,*)' tinteger_8 = ', tinteger_8,' @ kind =', long8 write(*,*)' tinteger_9 = ', tinteger_9,' @ kind =', long9 write(*,*)' tinteger_10 = ', tinteger_10,' @ kind =', long10 write(*,*)' tinteger_11 = ', tinteger_11,' @ kind =', long11 write(*,*)' tinteger_12 = ', tinteger_12,' @ kind =', long12 write(*,*)' ' end subroutine test_sel_int_kind end program test
if delete error-line, output of programm looks perfect:
./a.out testing integer selected_real_kind values longs1 = 32648 @ kind = 4 longs2 = 0 @ kind = 4 longs3 = 4202624 @ kind = 4 longs4 = 0 @ kind = 4 longs5 = 54 @ kind = 4 longs6 = 0 @ kind = 4 longs7 = 54 @ kind = 8 longs8 = 140223278864517 @ kind = 8 longs9 = 140735383116288 @ kind = 8 longs10 = 7595935609892856681 @ kind = 8 longs11 = 140735383119738 @ kind = 8 longs12 = 7 @ kind = 8 testing integer selected_int_kind values tinteger_1 = 0 @ kind = 1 tinteger_2 = 0 @ kind = 1 tinteger_3 = 0 @ kind = 2 tinteger_4 = 64 @ kind = 2 tinteger_5 = 0 @ kind = 4 tinteger_6 = 54 @ kind = 4 tinteger_7 = 0 @ kind = 4 tinteger_8 = 32 @ kind = 4 tinteger_9 = 0 @ kind = 4 tinteger_10 = 7595935609892856681 @ kind = 8 tinteger_11 = 140735383119738 @ kind = 8 tinteger_12 = 7 @ kind = 8 testing real selected_real_kind values treal_1 = 4.57495923e-41 treal_2 = 0.0000000 treal_3 = 5.88913056e-39 treal_4 = 0.0000000 treal_5 = 7.56701171e-44 treal_6 = 0.0000000 treal_7 = 2.66795448754273134e-322 treal_8 = 6.92795048341748080e-310 treal_9 = 6.95325179520640954e-310 treal_10 = 6.26338127621884380e+199 treal_11 = 6.95325179537686219e-310 treal_12 = 3.45845952088872581e-323
so why error? try on machine please , give me background information on error? great!
the right hand side of assignment statement triggers warning default integer literal constant - default integer because literal has no trailing kind qualifier. value of constant exceeds range of default integer compiler.
if assignment statement was
tinteger_12 = 12345678911_long12
where _long12 indicates kind of integer literal constant, warning should disappear.
as general rule, type , kind of expression (such expression right hand side of assignment statement causing error) determined solely primaries , operators within expression, , not context in expression used.
(your program supplied appears reference lot of undefined variables.)
Comments
Post a Comment