Re: Re: ++ BUG?? (fwd)

From: Date: Mon, 27 Nov 2000 23:41:27 +0000
Subject: Re: Re: ++ BUG?? (fwd)
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-39336@lists.php.net to get a copy of this message
> > On Mon, 27 Nov 2000, Zeev Suraski wrote the following to Ignacio...: > > > As a small proof of concept, what do you think the result of the following > > > file would be: > > > > > > void quiz(int foo, int bar) > > > { > > > printf("%d", foo+bar); > > > } > > > > > > void main() > > > { > > > int i=0; > > > > > > quiz(i++, i++); > > > } > > > > > > Zeev > > > Hint: If you came up with any numerical answer, you're wrong. > > > > "Would be", or "is"? I get 1. > Huh? Wha? Oh great. First my logic fails me, now my math :) I think the point that Zeev was trying to make was that there's no guarantee about the order of evaluation of parameters to a function. (However the answer will be 1 regardless of which way it worked 0+1 = 1+0. Perhaps printf 2*foo + bar; ). C/C++ requires that the arguments to a function be completely evaluated (and all side-effects posted) prior to entering the function, but the implementation is free to evaluate the arguments in any order (and presumably side-effects can be used to determine this ordering for a particular implementation) HTH, Simon

« previous php.dev (#39336) next »