Just amusing...
-
This may be a code signature
-
...if you replace the "magic numbers" with variables, this will make sense to do this way...in a readability sort of way.
Well. Not if it's the SAME variable! int x = z + y - z;
-
Well. Not if it's the SAME variable! int x = z + y - z;
-
What if z is volatile? This would mean that the value of z could change between the add and the subtraction.
Learn from the mistakes of others, you may not live long enough to make them all yourself.
What if z is volatile? If Z is volatile, then the code would go from being an idiosyncrasy to a horror, since the two reads would not be equivalent but there would be no sequence point to guarantee which would happen first. In some cases, it's fine to read a volatile variable twice without an intervening sequence point (e.g. using something like while (*mem != *mem); to determine whether a flash chip is busy). If the order in which the reads take place won't matter, then it won't matter if the compiler rearranges them. On the other hand, in an expression like foo = vol + something - vol, the effect on foo if vol changes will be indeterminate. Far better would be something like foo = vol + something; foo -= vol;. Under that scenario, the semantics if vol changes would be clear.
-
...if you replace the "magic numbers" with variables, this will make sense to do this way...in a readability sort of way.