Main Content

Function not called

Function is defined but not called

Description

This check on a function definition determines if the function is called anywhere in the code. This check is disabled if your code does not contain a main function.

Use this check to satisfy ISO® 26262 requirements about function coverage. For example, see table 15 of ISO 26262, part 6.

Note

This check is not turned on by default. To turn on this check, you must specify the appropriate analysis option. For more information, see Detect uncalled functions (-uncalled-function-checks).

Examples

expand all

#define max 100
int var;
int getValue(void);
int getSaturation(void);

void reset() {
    var=0;
}

void main() {
    int saturation = getSaturation(),val;
    for(int index=1; index<=max; index++) {
        val = getValue();
        if(val>0 && val<10)
            var += val;
        if(var > saturation)
            var=0;
    }
}

In this example, the function reset is defined but not called. Therefore, a gray Function not called check appears on the definition of reset.

Correction: Call Function

One possible correction is to call the function reset. In this example, the function call reset serves the same purpose as instruction var=0;. Therefore, replace the instruction with the function call.

#define max 100

int var;
int getValue(void);
int getSaturation(void);

void reset() {
    var=0;
}

void main() {
    int saturation = getSaturation(),val;
    for(int index=1; index<=max; index++) {
        val = getValue();
        if(val>0 && val<10)
            var += val;
        if(var > saturation)
            reset();
    }
}

#define max 100

int var;
int numberOfResets;
int getValue();
int getSaturation();

void updateCounter() {
  numberOfResets++;
}

void reset() {
  updateCounter();
  var=0;
}

void main() {
  int saturation = getSaturation(),val;
  for(int index=1; index<=max; index++) {
    val = getValue();
    if(val>0 && val<10)
      var += val;
    if(var > saturation) {
      numberOfResets++;
      var=0;
    }
  }
}

In this example, the function reset is defined but not called. Since the function updateCounter is called only from reset, a gray Function not called error appears on the definition of updateCounter.

Correction: Call Function

One possible correction is to call the function reset. In this example, the function call reset serves the same purpose as the instructions in the branch of if(var > saturation). Therefore, replace the instructions with the function call.

#define max 100

int var;
int numberOfResets;
int getValue(void);
int getSaturation(void);

void updateCounter() {
  numberOfResets++;
}

void reset() {
  updateCounter();
  var=0;
}

void main() {
  int saturation = getSaturation(),val;
  for(int index=1; index<=max; index++) {
    val = getValue();
    if(val>0 && val<10)
      var += val;
    if(var > saturation)
      reset();
  }
}

Check Information

Group: Data flow
Language: C | C++
Acronym: FNC