Main Content

Number of Call Occurrences

Number of calls in function body

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 specifies the number of function calls in the body of a function.

This metric includes:

  • Calls in unreachable code.

  • Calls to standard library functions.

  • Calls to constructors and destructors.

The metric excludes:

  • Calls through a function pointer.

  • Calls to virtual functions.

  • Calls to assert. Polyspace® considers assert as a macro and not a function.

  • Inlined functions. Compilers might inline certain function calls, such as the default constructors and destructors.

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 occurrences 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

Version History

expand all