replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Pure functions as procedure arguments
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 

Pure functions as procedure arguments

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



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat Oct 30, 2010 3:04 pm    Post subject: Pure functions as procedure arguments Reply with quote

I found a bug in the compiler (version 5.5). When passing a pure function as an argument to another pure function, the compiler gives an error that the argument is not declared as INTENT (IN). But this is not required, and somewhat meaningless for function arguments I believe. (I'm compiling in Checkmate mode but that shouldn't matter).

e.g. I write some code which finds the maximum of a function passed in as an argument on some interval (A, B). I get the error with this code (I provide only a dummy implementation here).

Code:


MODULE CALCULUS

CONTAINS

   PURE FUNCTION MAXIMISE(A, B, FUNC)
      REAL, INTENT (IN) :: A, B
      INTERFACE
         PURE FUNCTION FUNC(X)
            REAL, INTENT (IN) :: X
            REAL :: FUNC                  !<< Compiler complains here
         END FUNCTION FUNC
      END INTERFACE

      ! Here I just return the value mid-way between A and B
      MAXIMISE = FUNC((A+B)*0.5)

   END FUNCTION MAXIMISE

END MODULE CALCULUS



If I remove the PURE specifiers it compiles ok. I think this should be easy to fix for the next release. Any thoughts Paul? Very Happy
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Sat Oct 30, 2010 4:41 pm    Post subject: Reply with quote

I think you are right about it probably being easy to fix but the next release is currently being built.

Try using /ignore for the given error number to see if this will provide a work-around for now.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Tue Nov 02, 2010 7:27 am    Post subject: Reply with quote

Thanks for the quick response and confirmation Paul. I didn't know the new release was so close.

Well you can fix this in the release after that Very Happy.

I will play with ignoring the error number, but my current work-around is to take out the PURE keywords. I'm not sure the compiler takes much notice anyway in terms of generating efficient code, but only does extra compiler checks.
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Mon Jan 10, 2011 12:34 pm    Post subject: Reply with quote

I'm using version 6 of FTN95 now.

I have put the pure keywords back in as i feel it helps me to
document what is pure and what is not.

I have added /ignore 826 as a temporary fix. Trouble is, I have missed
some genuine errors as this fix is a little aggressive.

Incidently other compilers I have tried (intel, g95, gfortran, absoft) don't have this bug. Wink
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Jan 10, 2011 4:12 pm    Post subject: Reply with quote

I am looking at this right now and the short term fix is to add the INTENT(IN) attribute for the procedure argument ...

Code:
MODULE CALCULUS

CONTAINS

   PURE FUNCTION MAXIMISE(A, B, FUNC)
      REAL, INTENT (IN) :: A, B
      INTERFACE
         PURE FUNCTION FUNC(X)
            REAL, INTENT (IN) :: X
            REAL, INTENT (IN) :: FUNC        !<< Compiler does not complain here
         END FUNCTION FUNC
      END INTERFACE

      ! Here I just return the value mid-way between A and B
      MAXIMISE = FUNC((A+B)*0.5)

   END FUNCTION MAXIMISE

END MODULE CALCULUS
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


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

PostPosted: Mon Jan 10, 2011 4:55 pm    Post subject: Reply with quote

This bug has now been fixed for the next release.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Tue Jan 11, 2011 12:48 am    Post subject: Reply with quote

Thanks Paul, it's good to know you have fixed it.
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2621
Location: Sydney

PostPosted: Tue Jan 11, 2011 2:52 am    Post subject: Reply with quote

In the code example above, should MAXIMISE be declared as REAL ?
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Tue Jan 11, 2011 8:34 am    Post subject: Re: Reply with quote

JohnCampbell wrote:
In the code example above, should MAXIMISE be declared as REAL ?


Yes, you are correct. As is stands MAXIMISE is an integer function.
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