Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Why is the execution order of subexpressions undefined?

by BrowserUk (Patriarch)
on Apr 12, 2005 at 13:04 UTC ( [id://446971]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Why is the execution order of subexpressions undefined?
in thread Why is the execution order of subexpressions undefined?

As far as I can tell from how my thinking on the problem has gone, there is only one situation where execution order can affect the outome of a statement. That can be summarised as:

Any statement where a single variable is referenced twice or more, and where one of the references is as an lvalue and the lvalue reference come before another reference, can be subject to an evaluation order dependancy.

The major culprits from what I can divine/remember are autoincrement and autodecrememt, but it obviously includes assignment.

I think that the rule I suggested to Tye, that subexpressions are evaluated first; then precedence order; then left to right within precedence order. pretty much covers the entire definition.

But I also think that defining that parenthesised subexpressions will always be evaluated before the expressions they form a part of, and that multiple subexpressions will be evaluated left to right is the major part. Indeed, I think that this reflects current practice, and that defining it would simply formalise that. There may be exceptions, but I am not aware of any--yet! :)

This formalisation would allow the programmer to define the order in which they want compound expressions to be evaluated and place the responsibility firmly upon their shoulders--but give them the tool to get it right, for sure.

I haven't gotten to do much with pugs yet, but maybe it will fall out of that.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?
  • Comment on Re^4: Why is the execution order of subexpressions undefined?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://446971]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found