Fun with initialization order
Here's something I meant to post ages ago, when I was doing J2ME to Flash conversions, and got caught out by assumptions about the evaluation order of values passed to a method or to initialize an array. It's one of those really subtle issues that had me scratching my head to figure out what had gone wrong in a piece of code.
Consider the following (pseudo)code:
Now what would you expect the output to be? I had unwittingly assumed the result would consistently be:
arr: [1, 2, 3]
val1: 1, val2: 2, val3: 3
As it turns out, the answer varies from language to language (which is why I got snagged by code working 'correctly' in one language but 'breaking' in another):
Java:
Result:
arr: [1, 2, 3]
val1: 1, val2: 2, val3: 3
Actionscript:
Result:
arr: [3, 2, 1]
val1: 3, val2: 2, val3: 1
Some others:
C++ undefined:
C# guaranteed to be right to left:
