Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
else statement about Rule2.1
#3
The following response assumes that "a" is not volatile.

A statement with no executable code is not considered to be unreachable. This includes null statements and empty compound statements. The same applies to a default statement which contains no executable code.

The "else { ; } " is therefore not considered as unreachable code and is compliant with this rule.

The "else { y = 0; }" is unreachable as the statement contains code that would be executed if that control flow path had been reached.

However the above code does violate rule 14.3, since the condition "a >= 5" is an invariant as it will always evaluate to true due to the previous condition "a < 5 ".
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)