Main Content

Number of Local Non-Static Variables

Total number of local variables in function

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 provides the number of declared local variables in a function.

The metric excludes static variables and temporary variables. To find number of static variables, use the metric Number of Local Static Variables.

Examples

expand all

int flag();


int func(int param) {
  int var_1;
  int var_2;
  if (flag()) {
      int var_3;
      int var_4;
    } else {
      int var_5;
    }
}

In this example, the number of local non-static variables in func is 5. The number does not include the function arguments and return value.

typedef struct myStruct{
   char  arr1[50];
   char  arr2[50];
   int   val;
} myStruct;


void func(void) {
  myStruct var;
  char localArr[50];
}

In this example, the number of local non-static variables in func is 2: the structured variable var and the array localArr.

class Rectangle {
    int width, height;
  public:
    void set (int,int);
    int area (void);
} rect;

int Rectangle::area (void) {
    int temp;
    temp = width * height;
    return(temp);
}

In this example, the number of local non-static variables in Rectangle::area is 1: the variable temp.

Metric Information

Group: Function
Acronym: LOCAL_VARS
HIS Metric: No

Version History

Introduced in R2017a

expand all