Gotos in switches and Rule 6-4-5 - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.6 Statements (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=135) +---- Thread: Gotos in switches and Rule 6-4-5 (/showthread.php?tid=1477) |
Gotos in switches and Rule 6-4-5 - rgamble - 01-03-2019 Consider the following example: Code: typedef unsigned short uint16_t; Re: Gotos in switches and Rule 6-4-5 - misra cpp - 10-04-2019 You are right, your example violates 6-4-5. When 6-4-3 says jump-statements (which includes goto) "are permitted within the compound statements forming the body of a switch-clause", it means that you can write code like: switch(x) { case 1: { goto l1; // some code l1: // more code break; } case 2: ++x; break; default: break; } not that you can use goto to leave the switch statement or jump out of the compound statement following the "case" keyword. |