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 

Undefined function argument

 
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: 268

PostPosted: Mon Apr 04, 2022 7:02 am    Post subject: Undefined function argument Reply with quote

The following program creates an array ia, and then calls function f1, which in turn calls function f2 to assign some values to the array. Function f2 apparently is returning ia as undefined. If you change f2 to a subroutine, the behaviour is as expected.

I am using FTN95 version 8.83. I have not tried this program with other versions.

Code:
Module m
   Integer, Dimension(:), Allocatable, Public :: ia
Contains
!
 Subroutine s1 (n)
   Integer, Intent(In) :: n
!
   Allocate (ia(n))
   Return
 End Subroutine s1
!
 Function f1()
   Integer :: f1
   f1 = f2(ia(:))
   print*,'f1:',ia(:)
!
   Return
 End Function f1
!
 Function f2(ia2)
   Integer :: f2
   Integer, Dimension(:), Intent(Out) :: ia2
!
   ia2(:) = 1
   Print*,'f2:',ia2(:)
   f2 = 0
   Return
 End Function f2
End Module m
!
Program p
   Use m
   Integer :: i

   Call s1(5)
   i = f1()
End Program p
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Apr 04, 2022 8:16 am    Post subject: Reply with quote

Simon

At the moment I don't think that this is a regression in FTN95 and it is probably a bug that needs fixing.

The failure relates to passing the array section in the line
Code:
   f1 = f2(ia(:))

If you replace this line with
Code:
   f1 = f2(ia)

then the program runs correctly.
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Mon Apr 04, 2022 4:09 pm    Post subject: Reply with quote

Thanks Paul.
I can certainly implement
Code:
f1 = f2(ia)

in a few cases. But since it is not always a simple option, I will look into converting f2 to a subroutine, which seems to avoid the problem too.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Sat Oct 08, 2022 5:34 pm    Post subject: Reply with quote

This failure has now been fixed for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
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