Main Content

Estimated Function Coupling

Measure of complexity between levels of call tree

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 an approximate measure of complexity between different levels of the call tree. The metric is defined as:

number of call occurrencesnumber of function definitions + 1(1)
A negative value of this metric implies your code contains several unused functions, because your code has more function definitions than function calls. A positive value might indicate that the functions in your source file call each other often. This metric can be an estimate of the interdependency of the functions in a source file. You can use Polyspace Guideline checkers to set threshold for various code metric and check the complexity of your code. See Reduce Software Complexity by Using Polyspace Checkers.

This metric:

  • Counts function calls and function definitions in the current file only.

    It does not count function definitions in a header file included in the current file.

  • Treats static and inline functions like any other function.

Examples

expand all

void checkBounds(int *);
int getUnboundedValue();

int getBoundedValue(void) {
    int num = getUnboundedValue();
    checkBounds(&num);
    return num;
}

void main() {
    int input1=getBoundedValue(), input2= getBoundedValue(), prod;
    prod = input1 * input2;
    checkBounds(&prod);
}

In this example, there are:

  • 5 call occurrences. Both getBoundedValue and checkBounds are called twice and getUnboundedValue is called once.

  • 2 function definitions. main and getBoundedValue are defined.

Therefore, the Estimated function coupling is 5 - 2 + 1 = 4.

int foobar(int a, int b){ 
    return a+b; 
} 

int bar(int b){ 
    return b+2; 
} 

int foo(int a){ 
    return a<<2; 
} 

int main(int x){ 
    foobar(x,x+2); 
    return 0; 
}

This example shows how you can get a negative estimated function coupling result. In this example, you see:

  • 1 function call in main.

  • 4 defined functions: foobar, bar, foo, and main.

Therefore, the estimated function coupling is 1 - 4 + 1 = -2.

Metric Information

Group: File
Acronym: FCO
HIS Metric: No

Version History

expand all