Rule 15.7, 16.4, side-effects and statements. - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21) +---- Forum: 8.15 Control flow (https://forum.misra.org.uk/forumdisplay.php?fid=170) +---- Thread: Rule 15.7, 16.4, side-effects and statements. (/showthread.php?tid=1330) |
Rule 15.7, 16.4, side-effects and statements. - RichardC - 04-04-2017 Rule 15.7 "if...else if terminated by else" refers to "Rule 16.5". However, there appears to be a stronger relationship with 16.4: "Every switch shall have a default label". Should 16.4 be linked to 15.7? In my opinion, there is a slight inconsistency between the rule rationale for 15.7 and 16.4 and what might be read as being covered. Starting with Rule 15.7, the amplification requires a side-effect or a comment. Would you agree that this interpretation results in the following examples being 'non-compliant'? Code: void f1 (int x, int y) And the following examples would be compliant: Code: void f6 (int x, int y) For Rule 16.4, the amplification requires a 'statement'. What do you feel is that status of the following examples? Code: void f9 (int x) My reading of the Rationale is that the goal is have a 'defensive' comment unless the else does something, ie. the comment acts as a form of "Annotation". Alternatively, going just from the rationale, I would mark the above functions as Compliant/Non-Compliant as follows:
What is the view of the MISRA C group on this? |