A little caution note on chaining compound assignment.

First of, what is a compound assignment.? A compound assignment is when you use an operator in conjunction with the assignment operator
a += b; // The same as a = a + b
Now consider that you want to write a swap routine using XOR
a=a^b;
b=a^b;
a=a^b;
this could be transformed to compound operators
a^=b;
b^=a;
a^=b;
If you haven't read the spec on how assignments works, you would think that chaining these operators would be the same
a^=b^=a^=b;
But you will be surprised to learn that the latter two pieces of code behave differently.

Chapter 7.16.2 in the C# specification explains what is going on. When using the compound operator the left side operand is evaluated only once. this means in practice that when you chain the operators like in the last example, then all the left side operands are evaluated before any execution, thus  the chain doesn't get the intermediate a and b updated as when you make it line by line.

Comments

  1. The king casino is good, it just does not seem to
    The king casino is good, it just does 더킹카지노 not seem to The king casino is good, it just does not seem to The king casino is good, it just does not seem 바카라사이트 to The king casino is 코인카지노 good, it just does not seem to

    ReplyDelete
  2. It’s solely pure that the best on-line casino would have a world-class loyalty program. That is why we’ve created a free loyalty programme that allows you to|that permits you to} earn points each time you place a guess, you will be able to|which you'll} redeem for bonus credit. We consider in going above and past at Jackpot City, and that’s reflected each in our NZ casino bonus provides 빅카지노 and our loyalty program. Some of the aforementioned choices could solely be out there for deposits. Credit Cards and PayNearMe, most notably, are only for including cash to your account stability. Users that elected to deposit with these strategies want to|might need to} select a unique choice when it’s time to cash out.

    ReplyDelete

Post a Comment