Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA C:1998 Rule 58
#1
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)
{
FUNC_RESULT result;
......
......
.......

switch(x)
            {
            case 0:
                  result = checkInitVars();
                   /* If checkInitVars is a success, then call
                    * the startOperation too. Else, break. */
                  if (SUCCESS != result)
                     {
                      /* something not fine here, get out. */
                      break; /* Is the break here OKAY? */
                      }
                
                 /* Initialization is fine, start the job! */
                 result = startOperation();
                 break;

            case 1:
                  result = checkInitVars();
                  if (SUCCESS == result)
                     {
                      result = startOperation();
                      }
                  break;
            
             default:
                    result = FAILED;
                    break;
            }
.....
.....
.....
return (result);
}

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.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)