Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rice!mora!saltzman From: saltzman@mora.rice.edu (Matthew Saltzman) Newsgroups: comp.lang.fortran Subject: Re: Function calls in the middle of subroutine CALLs? -- Is it standard fortran 77 ???? Message-ID: <10074@brazos.Rice.edu> Date: 20 Jul 90 21:31:51 GMT References: <57505@lanl.gov> <1990Jul20.153135.11273@ux1.cso.uiuc.edu> Sender: root@rice.edu Organization: Rice University Lines: 50 In article <1990Jul20.153135.11273@ux1.cso.uiuc.edu> hirchert@ux1.cso.uiuc.edu (Kurt Hirchert) writes: >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 . (A couple of other postings have asserted something similar.) I'm sorry, but I don't see how a compiler can practically enforce such a restriction. *Any* time a variable appears as an argument to a function, it's a candidate for modification. If I write X = F(Y) + Y + Z how can the compiler know if Y is modified by F()? F() doesn't need to even appear in the same source file as the statement. Detection of the modification at run-time seems to be an unreasonable restriction on optimization. F() could even modify Z, if Z appeared in COMMON. Am I missing something? > 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.) This is a reasonable specification, but it is not the same as "not allowed." My Sun FORTRAN compiler has no problem with the above construct (with F(Y) modifying Y). I understand that if I actually *did* do this, it would be at my peril. > d. All of the above contributes to my recommendation that you not use > functions with side-effects in Fortran. Yes! > [deleted] >Kurt W. Hirchert hirchert@ncsa.uiuc.edu >National Center for Supercomputing Applications Matthew Saltzman saltzman@rice.edu Disclaimer: Institutions can't have opinions.