View previous topic :: View next topic |
Author |
Message |
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Mon May 16, 2022 11:01 am Post subject: Incorrect result of Present |
|
|
FTN95 fails to identify that the optional argument, i, in f2 is not present. I believe that the code is invalid Fortran, and that the External declaration in line 3 needs to be replaced by the commented-out Interface. As it is, FTN95 indicates that the optional argument, i, is present, whereas other compilers generate a run-time error. The argument i is correctly indicated as not present if the interface block is used.
!
Code: | Module m1
Contains
Function f1(f)
Integer :: f1
Integer, External :: f
! Interface
! Function f(i)
! Integer :: f
! Integer, Intent(In), Optional :: i
! End Function f
! End Interface
!
f1 = f()
Return
End Function f1
End Module m1
!
Module m2
Contains
Function f2(i)
Integer :: f2
Integer, Intent(In), Optional :: i
!
print*,Present(i)
f2 = 0
!
Return
End Function f2
End Module m2
!
Program p
Use m1
Use m2
Integer :: i
i = f1(f2)
End Program p |
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Mon May 16, 2022 11:22 am Post subject: |
|
|
Simon
I am not able to run your code at the moment.
Reading your code, it seems to me that the interface is required. Without the interface the code is not valid and the runtime outcome will be compiler dependent and maybe also random. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Mon May 23, 2022 7:01 am Post subject: |
|
|
Simon
The interface is required and (when omitted) FTN95 produces a runtime error report when /CHECK is used. |
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Mon May 23, 2022 2:19 pm Post subject: |
|
|
Understood Paul. Thanks |
|
Back to top |
|
|
|