This diagnostic rule is based on the software development guidelines developed by MISRA (Motor Industry Software Reliability Association).
This diagnostic rule is relevant only to C programs. The 'default' label should be either the first or the last label of a 'switch' statement. Following this rule makes the code clearer.
Here is an example of code triggering this warning:
void example_1(int cond)
{
switch (cond)
{
case 1:
DoSmth();
break;
default:
DoSmth2();
break;
case 3:
DoSmth3();
break;
}
}
To eliminate the warning, rewrite the code. For example:
void example_1(int cond)
{
switch (cond)
{
case 1:
DoSmth();
break;
case 3:
DoSmth3();
break;
default:
DoSmth2();
break;
}
}
This diagnostic is classified as:
|
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders:
Take
a chance!