27-09-2010, 10:47 AM
Hi All,
The Rule 15.2 says:
"An unconditional break statement shall terminate every non-empty switch clause"
i.e. The last statement in every switch clause shall be a break statement, or if the switch clause is a compound statement, then the last statement in the compound statement shall be a break statement.
I understand this as:
"In a switch clause, whatever be the path traversed by the code, there shall be one break statement at the end of every path"
In a project I have the following code for which I am not getting any MISRA warning (for case 1). If my understanding is incorrect, then somebody please correct me.
Best Regards,
Vinay Vastrad
The Rule 15.2 says:
"An unconditional break statement shall terminate every non-empty switch clause"
i.e. The last statement in every switch clause shall be a break statement, or if the switch clause is a compound statement, then the last statement in the compound statement shall be a break statement.
I understand this as:
"In a switch clause, whatever be the path traversed by the code, there shall be one break statement at the end of every path"
In a project I have the following code for which I am not getting any MISRA warning (for case 1). If my understanding is incorrect, then somebody please correct me.
Code:
switch (variable_1)
{
case 0:
{
// some code here;
break;
}
case 1:
{
// some code here;
if (variable_2 == 0)
{
break;
}
}
default:
break;
}
Best Regards,
Vinay Vastrad