Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 2.2 - dead code
#5
There are various issues raised by the original question and subsequent discussion which we will address in turn.



1. Rule 2.2 applies to operators not statements. 

  It is not a question of whether a whole statement is dead code, but whether there is an operation within the expression that has no effect on the program behaviour.



2. There are two operators of interest in this macro expansion.  First is the operation
  1u << (bit)  which is expanded to 1u << ( 0 )
  The shift operation has no effect on the program behaviour since shifting any value by 0 always produces the same answer.  Therefore the "<<(0)" can be removed and there is a violation of rule 2.2.

3. The second operation of interest is the cast which in this macro expansion has no effect and therefore is strictly speaking a violation of rule 2.2.
  However we agree with the previous poster that this was probably not what was intended by this rule. We will revisit this issue at a later date.
Posted by and on behalf of the MISRA C Working Group


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)