forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Incorrect result of Present

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
simon



Joined: 05 Jul 2006
Posts: 226

PostPosted: Mon May 16, 2022 11:01 am    Post subject: Incorrect result of Present Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7471
Location: Salford, UK

PostPosted: Mon May 16, 2022 11:22 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7471
Location: Salford, UK

PostPosted: Mon May 23, 2022 7:01 am    Post subject: Reply with quote

Simon

The interface is required and (when omitted) FTN95 produces a runtime error report when /CHECK is used.
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 226

PostPosted: Mon May 23, 2022 2:19 pm    Post subject: Reply with quote

Understood Paul. Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group