forums.silverfrost.com
Welcome to the Silverfrost forums

 Function arguments Goto page Previous  1, 2
Author Message
kaliuzhkin

Joined: 17 Sep 2012
Posts: 33

 Posted: Sat Nov 04, 2017 9:22 pm    Post subject: 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.
DanRRight

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

Posted: Sat Nov 04, 2017 11:04 pm    Post subject:

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 ()
JohnCampbell

Joined: 16 Feb 2006
Posts: 1994
Location: Sydney

Posted: Mon Nov 06, 2017 3:13 am    Post subject: Re:

 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 HourGoto page Previous  1, 2 Page 2 of 2

 Jump to: Select a forum Admin----------------Announcements FTN95----------------GeneralKBaseSupportSuggestionsClearWin+Plato64-bit FTN77----------------Support
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