30-07-2016, 10:46 AM
At first sight, I didn't believe that there was any dead code in your example. However, the question prompted me to re-read Rule 2.2 just to be sure. Having done so, I think you example does contain dead code according to the rule, even though common sense says that it doesn't.
The rule says
The uint8_t cast seems to satisfy this definition: it is an operator and it is certainly executed but removing it will have no effect on the program's behaviour. If that's the case, then this kind of dead code must be quite common. The essential type rules, for example, may well require insertion of casts that don't actually change the program's behaviour.
Maybe I'm misunderstanding what Rule 2.2 says but I would think that it's not intended to apply to your example.
The rule says
Quote:Any operation that is executed but whose removal would not affect program behaviour constitutes dead code
The uint8_t cast seems to satisfy this definition: it is an operator and it is certainly executed but removing it will have no effect on the program's behaviour. If that's the case, then this kind of dead code must be quite common. The essential type rules, for example, may well require insertion of casts that don't actually change the program's behaviour.
Maybe I'm misunderstanding what Rule 2.2 says but I would think that it's not intended to apply to your example.
<t></t>