Re: Re: ++ BUG?? (fwd)
| From: | Zeev Suraski | Date: | Sun, 26 Nov 2000 23:12:38 +0000 |
| Subject: | Re: Re: ++ BUG?? (fwd) | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-39167@lists.php.net to get a copy of this message | ||
At 21:45 26/11/2000, Ignacio Vazquez-Abrams wrote:
On Sun, 26 Nov 2000, Stanislav Malyshev wrote: IV>> are happening at the wrong time. They seem to be happening before the IV>> assignment instead of after the whole statement. Pre operations work as I do not get this. Why should ++ operator happen _after_ the assignment? Expression is evaluated as expression, and it does not know anything on the following assignment. $idx = ($idx++)%2 should leave $idx as 0. The PHP manual states "C-style ... operators". C only does the post(inc|dec) at the end of the statement, not after the expression.Which C is that? :) That's wrong. ++ and -- are operators. Operators obey to precedence rules inside expressions. Pretty much nothing in C is done on a per-statement basis. 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. -- Zeev Suraski <zeev@zend.com> CTO, Zend Technologies Ltd. http://www.zend.com/