ambiguous ?

Peter da Silva peter at ficc.uu.net
Tue Oct 24 01:07:06 AEST 1989


In article <14104 at lanl.gov> jlg at lanl.gov (Jim Giles) blathers:
> call given above is _illegal_ in Fortran if the order (or
> number) of function evaluations will effect the meaning of
> the program (that is, if FUNC has side-effects).

OK, so in FORTRAN the calling sequence is undefined, and in addition
you're not allowed to write any code where that matters. That's a
bloody great improvement.

> As I've already said,
> the solution I favor is to provide the user _explicit_ means
> of specifying whether a function has side-effects and then
> allowing the compiler to optimize _NON_SIDE-EFFECT_ function
> calls in any way it likes.

This has nothing to do with function calls that have side effects. We're
talking about evaluation order of arguments... expressions that have side
effects being used in arguments to function calls. In Fortran, you're just
not allowed to do that. In C, you can do it but your code may not be
portable. You have to watch out for dependencies among the arguments.

You may be confused because in Fortran the only way an expression can have
side effects is if it involves a function call.

Here's another question:

	In FORTRAN:

		INTEGER I, J
		INTEGER GETCH ! Returns next byte at input.
		DATA I /0/

		J = I * GETCH(5)
		J = 0 * GETCH(6)

Is this legal?

Is it guaranteed that GETCH(5) will be evaluated?
Is it guaranteed that GETCH(6) will be evaluated?

C makes these guarantees.
-- 
Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation.
Biz: peter at ficc.uu.net, +1 713 274 5180. Fun: peter at sugar.hackercorp.com. `-_-'
"I feared that the committee would decide to go with their previous        'U`
 decision unless I credibly pulled a full tantrum." -- dmr at alice.UUCP



More information about the Comp.lang.c mailing list