Re: Re: ++ BUG?? (fwd)
| From: | Zeev Suraski | Date: | Tue, 28 Nov 2000 07:46:48 +0000 |
| Subject: | Re: Re: ++ BUG?? (fwd) | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-39349@lists.php.net to get a copy of this message | ||
At 01:41 28-11-00, Simon Roberts wrote:
Wrong, as I said, no numeric answer would be correct, even though you're fairly close. '0' is also a valid result, since there's no guarantee as to whether the compiler would generate code to increment the variable before, or after, putting the previous value of the variable on the stack. For instance, Visual C++ would print out '0'. gcc would print out '1'. Both are valid results.On Mon, 27 Nov 2000, Zeev Suraski wrote the following to Ignacio...:followingAs a small proof of concept, what do you think the result of theHuh? 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; ).file would be: void quiz(int foo, int bar) {"Would be", or "is"? I get 1.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.
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)And it's also free to evaluate the side effects before, or after putting the values to the stack. Zeev -- Zeev Suraski <zeev@zend.com> CTO, Zend Technologies Ltd. http://www.zend.com/