View previous topic :: View next topic |
Author |
Message |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sat Oct 30, 2010 3:04 pm Post subject: Pure functions as procedure arguments |
|
|
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?  |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8255 Location: Salford, UK
|
Posted: Sat Oct 30, 2010 4:41 pm Post subject: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Tue Nov 02, 2010 7:27 am Post subject: |
|
|
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 .
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Mon Jan 10, 2011 12:34 pm Post subject: |
|
|
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.  |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8255 Location: Salford, UK
|
Posted: Mon Jan 10, 2011 4:12 pm Post subject: |
|
|
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 |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8255 Location: Salford, UK
|
Posted: Mon Jan 10, 2011 4:55 pm Post subject: |
|
|
This bug has now been fixed for the next release. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Tue Jan 11, 2011 12:48 am Post subject: |
|
|
Thanks Paul, it's good to know you have fixed it. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2621 Location: Sydney
|
Posted: Tue Jan 11, 2011 2:52 am Post subject: |
|
|
In the code example above, should MAXIMISE be declared as REAL ? |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Tue Jan 11, 2011 8:34 am Post subject: Re: |
|
|
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 |
|
 |
|