MISRA C:1998 Rule 58 - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: General Questions (https://forum.misra.org.uk/forumdisplay.php?fid=27) +--- Thread: MISRA C:1998 Rule 58 (/showthread.php?tid=370) |
MISRA C:1998 Rule 58 - himamsu - 29-06-2007 First, its good to see a forum on MISRA C. I was trying to understand rule 58 (break in a switch statement) from a control flow perspective. Here is a code snippet. Code: FUNC_RESULT aFunction(void) I would not want to call 'startOperation()' if my initialization variables are checked and returned to have correct values. In both the cases, the operation is started, only if the variables are correct. In light of that, I would like to know which of the case statement is okay and which are not according to the rule. Thanks in advance, Himamsu. Re: MISRA C:1998 Rule 58 - phaedsys - 01-07-2007 I would suggest the following. Code: switch(x) case 0 uses if-else. so you can catch a specific \"if\" and all esle will be the oposite state. depending on you system your default should return an error or place the system in a safe state. Why are you switching on X and then testing for result? I think you could have a more elegant solution. |