Main Content

Number of Lines Within Body

Number of lines 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 calculates the number of lines in a function body. When calculating the value of this metric, Polyspace® includes declarations, comments, blank lines, braces, and preprocessing directives. The initialization list of a member function is considered to be within the function body when calculating this metric.

If the function body contains a #include directive, the included file source code is also calculated as part of this metric.

This metric is not calculated for C++ function templates and its value is reported as Not computed.

Examples

expand all

void func(int);


int getSign(int arg) {
    int sign;
    if(arg<0) {
        sign=-1;
        func(-arg);
        /* func takes positive arguments */
    }
    else if(arg==0)
        sign=0;
    else {
        sign=1;
        func(arg);
    }
    return sign;
}

In this example, the number of executable lines of getSign is 13. The calculation includes:

  • The declaration int sign;.

  • The comment /* ... */.

  • The two lines with braces only.

class A {
    bool val;
    char c;
    int i;
public:
    A();
    void foo();
};

void A::foo() {}

A::A(): val(false),  
        c('A'),      
        i(42)        
{}

In this example, the function A::foo() has no executable lines. The value of the metric for this function is zero. The member function A::A() has three initializations in an initialization list. Polyspace considers these initializations to be within the function body. Because the function does not have an explicit return statement, the compiler generates an implicit return statement. Including the implicit return and the initializations, the value of this metric for A::A() is 4.

Metric Information

Group: Function
Acronym: FLIN
HIS Metric: No

Version History

expand all