Pergunta

I get an error message for compiling a Fortran 95 program:

$ gfortran test_SELECT_REAL_KIND.f90
test_SELECT_REAL_KIND.f90:148.23:
tINTEGER_12=12345678911
                       1
Error: Integer too big for its kind at (1). This check can be disabled with the option -fno-range-check

The program looks like 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,' at KIND =', LONG1
write(*,*)' longs2 = ', tlong2,' at KIND =', LONG2
write(*,*)' longs3 = ', tlong3,' at KIND =', LONG3
write(*,*)' longs4 = ', tlong4,' at KIND =', LONG4
write(*,*)' longs5 = ', tlong5,' at KIND =', LONG5
write(*,*)' longs6 = ', tlong6,' at KIND =', LONG6
write(*,*)' longs7 = ', tlong7,' at KIND =', LONG7
write(*,*)' longs8 = ', tlong8,' at KIND =', LONG8
write(*,*)' longs9 = ', tlong9,' at KIND =', LONG9
write(*,*)' longs10 = ', tlong10,' at KIND =', LONG10
write(*,*)' longs11 = ', tlong11,' at KIND =', LONG11
write(*,*)' longs12 = ', tlong12,' at 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,' at KIND =', LONG1
write(*,*)' tINTEGER_2 = ', tINTEGER_2,' at KIND =', LONG2
write(*,*)' tINTEGER_3 = ', tINTEGER_3,' at KIND =', LONG3
write(*,*)' tINTEGER_4 = ', tINTEGER_4,' at KIND =', LONG4
write(*,*)' tINTEGER_5 = ', tINTEGER_5,' at KIND =', LONG5
write(*,*)' tINTEGER_6 = ', tINTEGER_6,' at KIND =', LONG6
write(*,*)' tINTEGER_7 = ', tINTEGER_7,' at KIND =', LONG7
write(*,*)' tINTEGER_8 = ', tINTEGER_8,' at KIND =', LONG8
write(*,*)' tINTEGER_9 = ', tINTEGER_9,' at KIND =', LONG9
write(*,*)' tINTEGER_10 = ', tINTEGER_10,' at KIND =', LONG10
write(*,*)' tINTEGER_11 = ', tINTEGER_11,' at KIND =', LONG11
write(*,*)' tINTEGER_12 = ', tINTEGER_12,' at KIND =', LONG12
write(*,*)' '

end subroutine test_sel_int_kind

end program test

If I delete the error-line, the output of the programm looks perfect:

./a.out

 Testing INTEGER SELECTED_REAL_KIND values
  longs1 =        32648  at KIND =           4
  longs2 =            0  at KIND =           4
  longs3 =      4202624  at KIND =           4
  longs4 =            0  at KIND =           4
  longs5 =           54  at KIND =           4
  longs6 =            0  at KIND =           4
  longs7 =                    54  at KIND =           8
  longs8 =       140223278864517  at KIND =           8
  longs9 =       140735383116288  at KIND =           8
  longs10 =   7595935609892856681  at KIND =           8
  longs11 =       140735383119738  at KIND =           8
  longs12 =                     7  at KIND =           8


 Testing INTEGER SELECTED_INT_KIND values
  tINTEGER_1 =     0  at KIND =           1
  tINTEGER_2 =     0  at KIND =           1
  tINTEGER_3 =       0  at KIND =           2
  tINTEGER_4 =      64  at KIND =           2
  tINTEGER_5 =            0  at KIND =           4
  tINTEGER_6 =           54  at KIND =           4
  tINTEGER_7 =            0  at KIND =           4
  tINTEGER_8 =           32  at KIND =           4
  tINTEGER_9 =            0  at KIND =           4
  tINTEGER_10 =   7595935609892856681  at KIND =           8
  tINTEGER_11 =       140735383119738  at KIND =           8
  tINTEGER_12 =                     7  at 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 the do I get this error? Could you try it on your machine please and give me some background information on the error? It would be great!

Foi útil?

Solução

The right hand side of the assignment statement that triggers the warning is a default integer literal constant - it is default integer because the literal has no trailing kind qualifier. The value of that constant exceeds the range of default integer for your compiler.

If the assignment statement was

tINTEGER_12 = 12345678911_LONG12

where the _LONG12 indicates the kind of the integer literal constant, the warning should disappear.

As a general rule, the type and kind of an expression (such as the expression that is the right hand side of the assignment statement causing the error) is determined solely by the primaries and operators within the expression, and not be the context in which the expression is used.

(Your program as supplied appears to reference a lot of undefined variables.)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top