- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
an exemple :
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 ??
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
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve.
I trusted too much the compiler for this and lost hours looking for the bug :-/
I trusted too much the compiler for this and lost hours looking for the bug :-/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry to be confusing here - but on further research, the standard explicitly permits the rank to be different. Here is what the standard says:
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Even if the standard permits this "trap" to occur, the compiler could at least give a warning !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.

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