Re: Whacky increment/assignment logic with $foo++ vs ++$foo

From: Date: Fri, 02 Oct 2009 22:44:01 +0000
Subject: Re: Whacky increment/assignment logic with $foo++ vs ++$foo
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-298502@lists.php.net to get a copy of this message
>        int a = 2; >        b = a++; >        printf("b = [%d]\n", b); > > "b" would be 2 when printed.  However, after the second line (b = a++;) > finished executing, "a" would then be 3. Sure, but that code is perfectly clear. It's the odd special case where you assign the variable to itself, that's ambiguous. Like Daevid said, academic at this point -- but it might shed light on some compiler-design decisions that I don't have the vocabulary for. OTOH it could just a be a unique case with unpredictable results. Ben

« previous php.general (#298502) next »