Number of Call Occurrences

Number of calls in function body

Description

This metric specifies the number of function calls in the body of a function.

Calls through a function pointer are not counted. Calls in unreachable code and calls to standard library functions are counted. assert is considered as a macro and not a function, so it is not counted.

When calculating this metric in C++ code, Polyspace® ignores the implicit functions that the compiler generates, such as default constructors and destructors. User-defined constructors and destructors are counted as function calls. In a class hierarchy, if a base class has user-defined constructors, Polyspace counts the corresponding constructors of the derived classes as functions.

Examples

expand all

int func1(void);
int func2(void);


int foo() {
    return (func1() + func1()*func1() + 2*func2());
}

In this example, the number of call occurrences in foo is 4.

#include<stdio.h>
int getVal(void);


void fillArraySize10(int *arr) {
    for(int i=0; i<10; i++)
        arr[i]=getVal();
}

int getVal(void) {
    int val;
    printf("Enter a value:");
    scanf("%d", &val);
    return val;
}

In this example, the number of call occurrences in fillArraySize10 is 1.

#include <stdio.h>
int fibonacci(int);

void main() {
 int count;
 printf("How many numbers ?");
 scanf("%d",&count);
 fibonacci(count);
}

int fibonacci(int num)
{
   if ( num == 0 )
      return 0;
   else if ( num == 1 )
      return 1;
   else
      return ( fibonacci(num-1) + fibonacci(num-2) );
} 

In this example, the number of call occurrences in fibonacci is 2.

                #include<iostream>
class A{
    public:
	A(){
		std::cout<<"Create A\n";
	}
	~A() = default;
	A(const A&)=default;
	A(A&&) = default;
	virtual void bar(){ std::cout<<"A";}
};
class B: public A{
    public:
	B() = default;
	 void bar() override {std::cout<<"B";}
};

void func(A& a){
	a.bar();
}

int main(){
	A obj;
	A obj2 = obj;
	B objB;
	func(obj);
	return 0;
}

In this example, the number of call occurances in main is three:

  1. The constructor of class A in A obj;. This user defined constructor counts as a function call.

  2. The constructor of class B in B objB;. Because the constructor of the base class A is user-defined, the constructor of B counts as a function call even though B::B() is declared as =default.

  3. The call to function func.

The class A uses the default or implicit copy constructor. The call to the copy constructor in A obj2 = obj; does not count as a function call.

Metric Information

Group: Function
Acronym: NCALLS
HIS Metric: No