Path: utzoo!attcan!uunet!maverick.ksu.ksu.edu!ux1.cso.uiuc.edu!hirchert From: hirchert@ux1.cso.uiuc.edu (Kurt Hirchert) Newsgroups: comp.lang.fortran Subject: Re: Function calls in the middle of subroutine CALLs? -- Is it standard fortran 77 ???? Message-ID: <1990Jul20.153135.11273@ux1.cso.uiuc.edu> Date: 20 Jul 90 15:31:35 GMT References: <57505@lanl.gov> Organization: National Center for Supercomputing Applications Lines: 47 1. On the subject of functions with side effects: a. Fortran allows functions with side effects. b. However, you are not allowed to use a function with a side effect if that side effect could change the value of any other expression or subexpression in the same statement. (The one exception to this general rule is that in a statement of the form IF(), a side-effect in _can_ affect . c. Fortran does not guarantee that your function with side-effects will be executed. If the expression in which it appears can be evaluated without it, your processor is free to skip the execution of the function. If there is a possibility of this occurring, whether or not your processor suppresses the execution of the function, the standard calls for you to consider the side-effects of the function to be undefined and prohibits your making use of them. (Since the standard does not limit the methods the processor can use in determining the expression value without calling the function, it has been argued that you should always treat function side-effects as undefined.) d. All of the above contributes to my recommendation that you not use functions with side-effects in Fortran. The programming style where everything is done by functions that return status codes may be a good style for programming in C, but in Fortran it is likely to give you problems, especially if you are trying to write portable code. (This is why the intrinsic random number generator and date and time inquiries in Fortran 90 were made subroutines rather than functions.) 2. On the subject of the order of evaluation: a. A left-to-right rule is used to determine the mathematical meaning of an expression. (A right-to-left rule is used for the ** operator.) Thus, A-B-C means (A-B)-C, not A-(B-C). b. In the absence of parentheses, processor is free to make mathematically equivalent transformations in performing the evaluation of the expression, even though the "equivalent" expressions may not produce the same result in machine arithmetic. For example, A-B-C may be evaluated as (A-B)-C, A-(B+C), (A-C)-B, -(B-(A-C), (-C+A)-B, etc. c. However, a processor must not violate parentheses. If your processor evaluates (A*B)*C as A*(B*C), it is broken! (Unless, of course, it can prove that this produces exactly the same machine result.) Ditto, evaluating A*(B+C) as A*B+A*C. The above rules apply equally to FORTRAN 66, FORTRAN 77, and Fortran 90, although the implications of the rules may not be evident on particular implementations of these standards (e.g., FORTRAN IV). -- Kurt W. Hirchert hirchert@ncsa.uiuc.edu National Center for Supercomputing Applications