14.10 /* no else needed */ - 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.14 Control Flow (https://forum.misra.org.uk/forumdisplay.php?fid=46) +---- Thread: 14.10 /* no else needed */ (/showthread.php?tid=682) |
14.10 /* no else needed */ - ABR - 22-10-2009 In rule 14.10 (all if..... else if constructs shall be terminated with an else clause": is the /* no else needed */ comment on the single if block with no else a suggestion for use in code, where seems useful? Re: 14.10 /* no else needed */ - jbezem - 27-10-2009 IMHO, no, a simple if-statement without an else-clause need not be accompanied by a comment indicating the lack of an else-clause. Also, no empty else-clause shall be required. Especially when simple if-statements are encountered, such comments would clutter the code and impair understandability. E.g.: Code: if (a == 1) Rule 14.10 explicitly refers to chained if ... else if ... else if ... statements, where for better clarity the braces around the subsequent if-statements are omitted. To compensate for the missing braces (and extra indentation), the final else-clause shall be provided. Regards, Johan Re: 14.10 /* no else needed */ - misra-c - 10-11-2009 The comment in the example indicates that no else clause is required in this case. It is not the intention of this rule to require such comments for a simple if statement that has no else clause. |