in reply to Re^3: Pre vs Post Incrementing variables
in thread Pre vs Post Incrementing variables
Who said anything about operand evaluation order? (How could there be an operand evaluation order for a unary operator.)
You did, or rather the passage you quoted. The expressions whose order of evaluation is not defined are those that are operands. The order of those that aren't operands — those that are statements — is well defined.
No, the list operator is not a unary operator.
So, not an lvalue.
It appears that Perl doesn't realise that ++$i returns an lvalue (thus the syntax error), but it does.
$ perl -E'sub { $_[0]="fred"; }->($i++); say $i' 1 $ perl -E'sub { $_[0]="fred"; }->(++$i); say $i' fred
Ah! That well know Perl keyword 'alias'....
You understood what that code did, right? Troll. It's actually an imported function, fyi.
"It" has everything to do with the fact that the evaluation order of sub-expressions is unspecified.
No, even if "it" was specified — it's currently left to right for all the operators involved — the results would be the same.
The fact that f( ++$n, ++$n ) passes an alias to $n, rather than the value resulting from the preincrement, is just another broken behaviour.
That's entirely possible.
It is equivalent to C allowing:
Perl passes args by reference and C can't, so I don't see your point. It is equivalent to C++ allowing:
#include <stdio.h> void f( int &a, int &b ) { printf( "a: %d, b: %d \n", a, b ); a = 3; b = 4; } int main( int argc, char ** argv ) { int x = 0; f( ++x, ++x ); printf( "x: %d \n", x ); return 0; }
Which it does:
$ g++ -o a a.cpp && a a: 2, b: 2 x: 4
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Pre vs Post Incrementing variables
by BrowserUk (Patriarch) on Sep 13, 2010 at 03:45 UTC | |
by ikegami (Patriarch) on Sep 13, 2010 at 05:42 UTC | |
by BrowserUk (Patriarch) on Sep 13, 2010 at 06:20 UTC | |
by ikegami (Patriarch) on Sep 13, 2010 at 07:54 UTC | |
by BrowserUk (Patriarch) on Sep 13, 2010 at 08:51 UTC | |
| |
by JavaFan (Canon) on Sep 13, 2010 at 08:45 UTC | |
by BrowserUk (Patriarch) on Sep 13, 2010 at 09:19 UTC | |
|