Path: utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!bu.edu!xylogics!world!burley From: burley@world.std.com (James C Burley) Newsgroups: comp.lang.fortran Subject: Re: Function calls in the middle of subroutine CALLs? -- Is it standard fortran 77 ???? Message-ID: Date: 19 Jul 90 08:17:17 GMT References: <6381@helios.TAMU.EDU> <1990Jul19.014856.13421@maytag.waterloo.edu> Sender: burley@world.std.com (James C Burley) Organization: The World Lines: 31 In-Reply-To: dmurdoch@watstat.uwaterloo.ca's message of 19 Jul 90 01:48:56 GMT In article <1990Jul19.014856.13421@maytag.waterloo.edu> dmurdoch@watstat.uwaterloo.ca (Duncan Murdoch) writes: Does the standard specify in what order the arguments will be evaluated? If they have side effects, it makes a big difference sometimes. I've been bitten by a bug caused by the lack of such specification in Pascal. The standard says arguments may be evaluated in any order by any implementation at any time -- a given implementation (compiler) is not even required to evaluate function refs in a procedure call the same way each time it compiles it or consistently among identical calls. The reasoning behind not specifying an order for these sorts of things is twofold (at least): one, there isn't a visual ordering in the procedure call (not everyone reads left to right naturally) and side effects in function calls are not naturally obvious, so writing code that used any ordering would result in harder-to-read code; two, it allows a compiler to perform optimizations that might not be obtainable given a mandated ordering (especially on machine with parallel computational units). If you need to do something like "CALL X(F(1),G(2))" and you care about the ordering, you should do the following instead: TEMP1 = F(1) TEMP2 = G(2) !Or the opposite order if you desire CALL X(TEMP1,TEMP2) That way the ordering is imposed on the optimizer only when necessary (as in this case) and is immediately obvious to anyone reading the code, without the need for further comments (it even suggests F and G might have side-effects though comments should still be used to clarify this, just in case someone says "aha! I'll make the code prettier by doing away with the temps!").