Main Content

Number of Function Parameters

Number of function arguments

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 function arguments.

If ellipsis is used to denote variable number of arguments, when calculating this metric, the ellipsis is not counted.

The recommended upper limit for this metric is 5. For less dependency between functions and fewer side effects, try to enforce an upper limit on this metric.

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

Examples

expand all

int initializeArray(int* arr, int size) {
}

In this example, initializeArray has two parameters.


int getValueInLoc(struct {int* arr; int size;}myArray, int loc) {
}

In this example, getValueInLoc has two parameters.

double average ( int num, ... )
{
    va_list arg;
    double sum = 0;
   
    va_start ( arg, num );
    
    for ( int x = 0; x < num; x++ )
    {
        sum += va_arg ( arg, double );
    }
    va_end ( arg);                  

    return sum / num;
}

In this example, average has one parameter. The ellipsis denoting variable number of arguments is not counted.

Metric Information

Group: Function
Acronym: PARAM
HIS Metric: Yes

Version History

expand all