Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Array rank checking

tonio
Beginner
819 Views
Hello,

an exemple :

program t

real*8, allocatable :: tab1(:)
real*8, pointer     :: tab2(:)
real*8              :: tab3(2)

allocate(tab1(2),tab2(2))

tab1 = 0.D0 ; tab2 = 0.D0 ; tab3 = 0.D0

call test(tab1)
call test(tab2)
call test(tab3)

contains
subroutine test(tab)
real*8 tab(2,2)

print*,tab

end subroutine test
end program t



The compilation gives the following error :

ifort -warn all test3.f90
fortcom: Error: test3.f90, line 11: The shape matching rules of actual arguments and dummy arguments have been violated. [TAB3]
call test(tab3)
----------^
compilation aborted for test3.f90 (code 1)


My question is why allocated arrays do not generate the errors I was waiting for ??

Message Edited by sblionel on 09-15-2005 12:44 PM

0 Kudos
5 Replies
Steven_L_Intel1
Employee
819 Views
ifort does not do run-time shape checking in the current version. It is something we hope to implement in the future. But I agree that the compiler, at compile time, should be able to notice that the ranks don't match. I'll suggest that to the developers.
0 Kudos
tonio
Beginner
819 Views
Thanks Steve.

I trusted too much the compiler for this and lost hours looking for the bug :-/
0 Kudos
Steven_L_Intel1
Employee
819 Views
Sorry to be confusing here - but on further research, the standard explicitly permits the rank to be different. Here is what the standard says:

18 An actual argument that represents an element sequence and corresponds to a dummy argument that is
19 an array is sequence associated with the dummy argument if the dummy argument is an explicit-shape
20 or assumed-size array. The rank and shape of the actual argument need not agree with the rank and
21 shape of the dummy argument, but the number of elements in the dummy argument shall not exceed
22 the number of elements in the element sequence of the actual argument. If the dummy argument is
23 assumed-size, the number of elements in the dummy argument is exactly the number of elements in the
24 element sequence.


In a more recent version of the compiler than the one you are using, the compiler would note that array tab3 had fewer elements than dummy argument tab and would give you a (different from what you saw) warning about that, but it has no way of knowing how many elements are in the allocatable arrays so it can't check.
0 Kudos
tonio
Beginner
819 Views
Even if the standard permits this "trap" to occur, the compiler could at least give a warning !
0 Kudos
Steven_L_Intel1
Employee
819 Views
No, we don't give warnings for standard-conforming behavior, and in fact there are many legitimate uses for this.

What we could do is add an optional run-time check that the array you're passing is at least as big as the declared size of the routine dummy argument, but that may or may not help you depending on what your error was.
0 Kudos
Reply