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 

Function arguments
Goto page Previous  1, 2
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
kaliuzhkin



Joined: 17 Sep 2012
Posts: 33

PostPosted: Sat Nov 04, 2017 9:22 pm    Post subject: Reply with quote

Success!!!

Calling program:

IMPLICIT NONE
INTEGER (SELECTED_INT_KIND(2)):: TwoDice, Tot, Total
!
MainLoop: DO !We will repeat this process indefinitely
Tot = TwoDice() !Call the function - roll the dice

DanRR had written: Dan,
When defining a function you need to add parentheses even with no arguments.
When using function - parentheses are omittable.
This is counterintuitive but that's how it is in Fortran

I misunderstood this. I took this to mean the parentheses have to be in the FUNCTION routine, not in the calling program. It’s the other way around.

On a different issue, I notice that John Campbell defines a function by “character*11 function time_string ()”

Counihan writes: “Since it is not necessary to use type-prefixed FUNCTION statements, and sometimes it can be cumbersome to do so (in Chapter 11 we shall meet other prefixes!), the practice is not recommended.”

Comments?

Dan K.
Back to top
View user's profile Send private message Send e-mail
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sat Nov 04, 2017 11:04 pm    Post subject: Reply with quote

With parentheses the functions in Fortran have holly mess. Suppose we have function called SomeFunction. Here are three cases where parentheses are not needed

Code:
Integer, external:: SomeFunction
SomeFunction = 1
i=winio@('%^bt[Run]',SomeFunction)

And here couple cases where they are needed
Code:
integer function SomeFunction()
i=SomeFunction ()
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Mon Nov 06, 2017 3:13 am    Post subject: Re: Reply with quote

kaliuzhkin wrote:
Counihan writes: “Since it is not necessary to use type-prefixed FUNCTION statements, and sometimes it can be cumbersome to do so (in Chapter 11 we shall meet other prefixes!), the practice is not recommended.”


Counihan has a different recommendation on labelling functions. Mine is to define the function type up front as it improves clarity of layout. Neither are illegal; it is just a matter of style.

I would also recommend to be consistent with your approach.

John
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 -> General All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
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