Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!ames!skipper!elxsi!maine From: maine@elxsi.dfrf.nasa.gov (Richard Maine) Newsgroups: comp.lang.fortran Subject: Re: another side effect question Message-ID: Date: 1 Aug 90 18:30:17 GMT References: <968@nikhefh.nikhef.nl> Sender: news@skipper.dfrf.nasa.gov Organization: NASA Dryden, Edwards, Cal. Lines: 71 In-reply-to: t19@nikhefh.nikhef.nl's message of 1 Aug 90 16:42:00 GMT On 1 Aug 90 16:42:00 GMT, t19@nikhefh.nikhef.nl (Geert J v Oldenborgh) said: Geert> While on the subject of side effect of functions, is there Geert> anything in the (77) standard which prohibits Geert> PRINT *,AAP(1.) Geert> END Geert> REAL FUNCTION AAP(X) Geert> PRINT *,'THIS IS AAP' Geert> AAP = X Geert> END Geert> None of the Fortrans I use properly prints this. Yet, I find Geert> it a useful construct to remind me which set of functions I am Geert> using (of course only printing on the first call). Yes, it is prohibited by section 12.11, "Restrictions on Function references and List Items", which reads: A function must not be referenced within an expression appearing anywhere in an input/output statement if such a reference causes an input/output statement to be executed. I subtlety of this restriction that annoys me relates to internal i/o. Internal i/o isn't "really" i/o. It is just doing format conversion, taking advantage of the Fortran runtime capabilities that happen to also be used for "real" i/o. Nonetheless, by the strict definitions of the standard, internal i/o does fall under the above restriction. Thus, I cannot do the following double precision time external tfmt character*12 tfmt ... write (*,*) tfmt(time) ... function tfmt(time) c Format a time value for printout. double precision time character*12 tfmt integer itime(4) external hmsms c hmsms converts time from total seconds to an array of 4 integers c with hours, minutes, seconds, and milliseconds. c Omitted from this example. call hmsms(time,itime) write (tfmt,'(i2.2,1h:,i2.2,1h:,i2.2,1h.i3.3)') itime return end I have a routine simillar to tfmt, but to make it standard, I have to do the conversion without using the internal write. Not really too hard in this case, but its annoying that I have to. Some machines will let you get by with the internal write, but it is not standard and there do exist machines where it fails. I generally avoid calling all but the simplest functions in i/o statements because a function called in some context isn't even allowed to print out an error or debugging message (and most routines of any substantial content have places where error or debugging messages are appropriate). -- Richard Maine maine@elxsi.dfrf.nasa.gov [130.134.64.6]