Question

my code is a mix up of different bits and pieces from older code.

I would like to erase all never used functions in order to keep the code simple.

Is Klocwork the tool? How do I do it?

Thanks,

Moshe.

Was it helpful?

Solution

You could use the -p or -pg options to gcc to cause code to be added to the prologue and epilogue of every function so that a profile database is written when the program executes. The tool prof is used to analyze the output from -p and gprof for -pg. These tools produce reports showing what functions were used, how many calls, and how much time was spent in each. Unused functions will be missing from the profile database.

You could also use gcov to get a report of what lines of code were actually executed. Functions never called will be executed 0 times....

OTHER TIPS

Klocwork will find unused function/methods. There is a special checker pack you can download on my.klocwork.com (if you have an account) that will give you these special checkers.

I am not familiar with Klocwork, but gcc has the warning option -Wunused-function that detects most uncalled functions. -Wunused-function is part of -Wall.

Klockwork doesnt detect uncalled functions. Its used for static analysis only.

You can check it like this:

foo()
{
   char *a;
   a = malloc(100);
}
bar()
{
   char a[100];
}

main()
{
   bar();
}

This would probably report leak in function foo which is actually uncalled. However as schot suggested you can look into compiler options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top