Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 15.7 and empty else statements without "else if"
#1
MISRA C 2012 Rule 15.7 states in the amplification that "The else statement shall contain at least either one side effect or a
comment." Does "The else statement" refers to any else statement or just the final else statement that is required
by the rule when there are one or more "else if" statements? Is the following example a violation of Rule 15.7 because the else
statement does not contain a side effect or comment or is it compliant because the else is not required by the rule?

Code:
typedef _Bool bool_t;
void foo(bool_t x);
void foo(bool_t x) {
    if (x) {
        ;
    }  
    else { }
}
<t></t>
#2
"The else statement" refers to the final else statement in a "if .. else if" construct.

Rule 15.7 does not apply to the above example because there is no "if... else if" construct in the example. No comment or side effect is required in this case.
Posted by and on behalf of the MISRA C Working Group


Forum Jump:


Users browsing this thread: 3 Guest(s)