Main Content

Number of Goto Statements

Number of goto statements

Description

Note

Use Bug Finder instead of Code Prover for computing code metrics. Support for computing code metrics in Code Prover will be removed in a future release. See Version History.

This metric measures the number of goto statements in a function.

break and continue statements are not counted.

The recommended upper limit on this metric is 0. For better readability of your code, avoid goto statements in your code. To detect use of goto statements, check for violations of MISRA C:2012 Rule 15.1.

To enforce limits on metrics, see Compute Code Complexity Metrics Using Polyspace.

Examples

expand all

#define SIZE 10
int initialize(int **arr, int loc);
void printString(int *);
void printErrorMessage(void);
void printExecutionMessage(void);


int main()
{
    int *arrayOfStrings[SIZE],len[SIZE],i;
    for ( i = 0; i < SIZE; i++ )
    {
        len[i] = initialize(arrayOfStrings,i);
    }

    for ( i = 0; i < SIZE; i++ )
    {
        if(len[i] == 0)
            goto emptyString;
        else
            goto nonEmptyString;
        loop: printExecutionMessage();
    }

emptyString:
    printErrorMessage();
    goto loop;
nonEmptyString:
    printString(arrayOfStrings[i]);
    goto loop;
}

In this example, the function main has 4 goto statements.

Metric Information

Group: Function
Acronym: GOTO
HIS Metric: Yes

Version History

expand all