📜 ⬆️ ⬇️

Is it true that people write insane code with overlapping side effects, while maintaining equanimity?

We offer you a translation of Raymond Chen’s article from The Old New Thing blog, which deals with problems of code relying on the order of evaluation of expressions - and all those who write foo (i ++, a [i]);
The order of evaluation of expressions is determined by the specific implementation, unless the language guarantees a certain order of evaluation. If, in addition to the result, the evaluation of an expression causes changes in the runtime environment, then it is said that this expression has side effects.
MSDN
In our internal mailing list about C #, a controversial question regularly arises, which concerns the correct interpretation of similar constructions:

a -= a *= a;
p[x++] = ++x;

:
? , , « » (IOCCC, International Obfuscated C Code Contest), — , - . , -, a -= a *= a p[x++] = ++x; « , !»
: «, ». , , , . , — 4 . , ; , , — , , .

, , : " ". , , .

-, . , :

total_cost = p->base_price + p->calculate_tax();

: , calculate_tax (const), , base_price — , base_price , . , , ( ), calculate_tax (tax) , ; , .

, , — .

, , , — , . ": ".

- : , , — . «, , , , . . !». - , . , — - , .

, — , . « , . , . . , ». , , , , .

, , . - , x ^= y ^= x ^= y C#, ++. , - , — , .



')

Source: https://habr.com/ru/post/333936/


All Articles