05-12-2014, 08:36 AM
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 ".
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