- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
The test-case below captures the gist of an error; where is the cause that the adjustable array is bigger than what has been passed in. It cannot be caught by the compiler; I understand. I am wondering is there a way (as in a flag) to catch it at run-time. Compiling with ifort /check:all Test.f90 won't do.
As you can imagine this is extracted from rather deep inside a combination of legacy and new program. In one of the test-cases of that program, it revealed itself as "access violation" but that was at a different location.
Abhi
---
Module OM
Implicit None
Integer :: M, N
Integer :: L
Contains
Subroutine Set()
M = 3; N = 5
End Subroutine Set
Subroutine Tech(K)
Integer :: K(N) ! Size is larger than what's passed; its incorrect.
Integer :: L
K = -1 ! any way to catch this error at run-time?
L = K(N) - 1 ! or here?
Write(*,"(2(A,X,I0,X))") "in Tech: K(N) =", K(N), " and L =", L
End Subroutine Tech
End Module OM
Program Test
Use OM
Implicit None
Integer, Allocatable :: I(:)
Call Set()
Allocate(I(M))
I = 0
Call Tech(I)
Write(*,"(A,X,I0,X)") "after the call L =", L
End Program Test
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you try /check:bounds?
A question: can you not use assumed-shape array argument and if the length is inadequate, do some error handling instead?
subroutine Tech(K) ! Argument list integer :: K(:) !<-- assumed shape .. if ( size(K) < N ) then ! Size is shorter than desired, do the needful ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi FortranFan
Thanks for your comment.
(a) As I mentioned, this doesn't get trapped with /check:all. So, no /check:bounds won't catch it.
(b) Yes, there are ways to rectify this. But since this is coming from some legacy things, I am wondering if it can't be caught.
Abhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel Fortran doesn't offer a check for this sort of thing. It would require passing extra information in a way that would break existing programs.
Better to use assumed-shape arrays.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page