链接已复制
[plain]integer array(5) array = 0 print *, array(6) end[/plain]C:Projects>ifort /check:bounds t.f90
Intel Visual Fortran Compiler Professional for applications running on IA-32,
Version 11.1 Build 20090903 Package ID: w_cprof_p_11.1.046
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.
t.f90(5): error #5560: Subscript #1 of the array ARRAY has value 6 which is greater than the upper bound of 5
print *, array(6)
---------^
(I did this on Windows but it will be the same on Linux.) I will comment that it is rare that the Fortran source will be so blatant about the indexing error as to allow the compiler to catch this at compile time, but it can do so.
[plain]integer array(5) array = 0 print *, array(6) end[/plain]C:Projects>ifort /check:bounds t.f90
Intel Visual Fortran Compiler Professional for applications running on IA-32,
Version 11.1 Build 20090903 Package ID: w_cprof_p_11.1.046
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.
t.f90(5): error #5560: Subscript #1 of the array ARRAY has value 6 which is greater than the upper bound of 5
print *, array(6)
---------^
(I did this on Windows but it will be the same on Linux.) I will comment that it is rare that the Fortran source will be so blatant about the indexing error as to allow the compiler to catch this at compile time, but it can do so.
Following on the previous discussion, what I am missing here?
When I explicitly access elements which are out of the array, I get neither compiler nor run-time errors.
Notice that I use the -check bounds flag when compiling the program.
pmginacio@hpc03 ~/.tmp/testbounds
$ ifort --version
ifort (IFORT) 13.1.3 20130607
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.
pmginacio@hpc03 ~/.tmp/testbounds
$ cat ./testbounds.f90
! Template program
program testbounds
implicit none
!variables declaration
real(8) :: dcm(9)
integer :: i
! inits
do i=1,size(dcm)
dcm(i)=i
end do
print *, dcm(6:14)
end program testbounds
pmginacio@hpc03 ~/.tmp/testbounds
$ ifort -check bounds -o testbounds testbounds.f90
pmginacio@hpc03 ~/.tmp/testbounds
$ ./testbounds
6.00000000000000 7.00000000000000 8.00000000000000
9.00000000000000 0.000000000000000E+000 0.000000000000000E+000
0.000000000000000E+000 2.121995790965272E-314 1.943555437610296E-316