- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, not at compile time. The -check bounds option enables a run-time check for out of bounds references.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On a side note, 'length' is not a very good variable name, is it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks as if the array bounds check doesn't happen when the subscript is part of an I/O list. It really should and I will let the developers know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Array bounds checking for I/O lists has been implemented for a future (2016) major release.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page