- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
We all know that Fortran may use both subroutine and function procedures. In general a difference between implementations of these ones is small. In particular it is more explicit.
Usually I use a function for small procedure (for example, to evaluate some value) and subroutine for larges pieces of code (something like a main method which is calling another function and subroutines).
I would like find out special features of functions and subroutines. Can Intel comment this one?
Oleg.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
More useful discussions on this subject have appeared (as recently as last month) on comp.lang.fortran Usenet group. It's a shame that Google has control of the archives and has packed them with spam.
Metcalf, Reid, and Cohen are emphatic in their textbooks that a subroutine should be used when "side effects" are required. Among the evident reasons are that a function could be invoked more than once in contexts where the order of events is undefined.
In the realm of intrinsics, an example would be bringing the use of legacy non-portable intrinsics system()/systemqq() into the new standard "call execute_command_line()" subroutine form. Adoption of this intrinsic shows that the standards committee agrees with the goal of eliminating side effects from function procedures.
Metcalf, Reid, and Cohen are emphatic in their textbooks that a subroutine should be used when "side effects" are required. Among the evident reasons are that a function could be invoked more than once in contexts where the order of events is undefined.
In the realm of intrinsics, an example would be bringing the use of legacy non-portable intrinsics system()/systemqq() into the new standard "call execute_command_line()" subroutine form. Adoption of this intrinsic shows that the standards committee agrees with the goal of eliminating side effects from function procedures.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adding to what Tim says, clearly there are uses where a function is required, such as when you want to use the value in an expression. But it is also a very common usage to have a function where the purpose of the function value is to return a success/failure status, in which case the function usually does have side effects.
The standard is quite particular about intrinsic procedures, since there are many contexts in the standard, such as specification expressions, where pretty much any intrinsic function is allowed. This is why intrinsic procedures that have side-effects or that modify their arguments are always defined as subroutines rather than functions, it's not really a desire to eliminate functions with side effects in general.
The standard is quite particular about intrinsic procedures, since there are many contexts in the standard, such as specification expressions, where pretty much any intrinsic function is allowed. This is why intrinsic procedures that have side-effects or that modify their arguments are always defined as subroutines rather than functions, it's not really a desire to eliminate functions with side effects in general.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page