- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I am wondering if there is a compiler option to trap a "shape" mismatch such as 1-D array being passed but subroutine declares it as a 2-D array or vice cersa.
For example,
Program Trap
Implicit None
Real :: A(10)
Call Test(A)
End Program Trap
Subroutine Test(B)
Implicit None
Real :: B(2,2)
B = 1.0
End Subroutine Test
Abhi
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That particular mismatch would be detected if you used /gen-interface /warn:interface . or if you used explicit interfaces (a good idea.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I am wondering if there is a compiler option to trap a "shape" mismatch such as 1-D array being passed but subroutine declares it as a 2-D array or vice cersa.
For example,
Program Trap
Implicit None
Real :: A(10)
Call Test(A)
End Program Trap
Subroutine Test(B)
Implicit None
Real :: B(2,2)
B = 1.0
End Subroutine Test
Abhi
This appears to be a legitimate combination of legacy and more recent Fortran, although I would hope not normal practice. It should even work, if used correctly (4 elements of a set to 1.0, rest undefined). If you would use f90 module subroutine or interface block, you could rule out this confusing usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve and Tim
Thanks for your answers. However, I did test the module and explicit interface before posting. (Sorry, I should have been more clear about it) and it does not trap the shape mismatch.
In fact, it kind of surprised me when this was NOT trapped. Although I have to survive through a lot of legacy code, I try my best to adhere to F2003 standard and corresponding best practices. But I must be missing something in this example.
Below is my sample program and corresponding log. For testing, I used the default "Debug" mode that has warn and gen interfaces. I am using WinXPP 64 bit, Xeon processor, VS 2005, and compiler 11.0.039 Beta as well as 10.1.024. There is no compilation error.
Module TestModule
Implicit None
Contains
Subroutine TestSub(B)
Implicit None
Real(8) :: B(2,2)
B = 1.0d0
End Subroutine TestSub
End Module TestModule
Program Test_ShapeMatching
Use TestModule
Implicit None
Real(8) :: A(9)
Interface
Subroutine AnotherTest(B)
Implicit None
Real(8) :: B(2,2)
End Subroutine AnotherTest
End Interface
A = 0.0d0
Call TestSub(A)
Print *, A
Call AnotherTest(A)
Print *, A
End program Test_ShapeMatching
Subroutine AnotherTest(B)
Implicit None
Real(8) :: B(2,2)
B = 1.0
End Subroutine AnotherTest
====
Build log:
Build Log |
|
Output |
Deleting intermediate files and output files for project 'Test_ShapeMatching', configuration 'Debug|Win32'. |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just wanted to make "noise" by saying that making the interface explicit (either using module or using an explicit interface) does not trap shape mismatch error. I put in the code and the build log in my previous post.
Abhi

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