[previous] 2001 [next] A 'goto' statement has been used.
Control flow

A goto statement has been used.

Use of a goto statement is generally discouraged in coding standards, although they can be justified in certain circumstances.

Note that backward jumps contribute to the number-of-backward-jumps (STBAK) metric and jumps out of control structures will contribute to the knot count (STKNT) metric.

For example:


/*PRQA S 2017,2201,2461,3227,3408,3416,3442,3447,3602 ++*/

extern volatile int n;
extern int ef(void);

extern int foo(int m)
{
    int i;
    int r = 0;

    while (n > 0)
    {
        for (i = 0; i < m; ++i)
        {
            r = ef();
            if (r < 0)
            {
                goto E;                 /* Message 2001 */
            }
        }
    }
E:  return r;                           /* Message 2015 */
}


MISRA C:2012 Rules applicable to message 2001:

Rule-15.1  (Advisory) The goto statement should not be used


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents