Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Auto Increment "magic" Inquiry

by GrandFather (Saint)
on Jan 04, 2007 at 22:16 UTC ( [id://593033]=note: print w/replies, xml ) Need Help??


in reply to Auto Increment "magic" Inquiry

Point B is the key.

Point C is tricky. The assertion that "++$i was performed on first, then $i++" is misleading. The distinction would only be relevant for ++$i++ which is illegal in any case. In the expression $i++ + --$i neither Perl nor C make any promises about the order in which the two sub expressions are evaluated. The second paragraph of Section A7 in "The C Programming Language (second edition)" (the K&R C book) makes that absolutely clear in the case of C (and assists in understanding the issue in Perl):

"... unless the definition of an operator guarantees that its operands are evaluated in a particular order, the implementation is free to evaluate operands in any order."

On the basis of that statement alone any of your tests involving addition are spurious. In particular note (from the same paragraph as cited above):

"... the order of evaluation of expressions is, with certain exceptions, undefined, even if the subexpressions involve side effects." (emphasis added)

Your colleague is either lucky or experienced with the particular implementation you are using. Watch out for changes between versions, platforms, C compiler and compiler options - one day you are going to get bit, and it will be particuarly nasty to diagnose!

Update: clarified the absolute clarity


DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found