Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out if a function is called within a C++ project?

Tags:

I'm trying to remove functions that are not used from a C++ project. Over time it's become bloated and I'm looking to remove functions that aren't used at all.

I have all the projects in a solution file in Visual Studio, but I use cmake so I can generate project files for another IDE if necessary (which is why this isn't tagged with visual-studio).

Does something like this exist? Where it'll analyze the source and tell me which functions are not called. I saw PC-Lint mentioned in a few questions here, but that doesn't seem to do this.

What I really want to do is call "Find all references" on each function and remove the functions not called, but doing this manually would take much too long.

like image 294
Joe Avatar asked Dec 10 '09 16:12

Joe


People also ask

What is main () in C?

Every C program has a primary (main) function that must be named main. If your code adheres to the Unicode programming model, you can use the wide-character version of main, wmain. The main function serves as the starting point for program execution.

What is function declaration in C?

A function consist of two parts: Declaration: the function's name, return type, and parameters (if any) Definition: the body of the function (code to be executed)

What happens before main function in C?

The _start Function. For most C and C++ programs, the true entry point is not main , it's the _start function. This function initializes the program runtime and invokes the program's main function. The use of _start is merely a general convention.


1 Answers

Use __declspec(deprecated) in front of the function declaration you want to get rid of. That will throw up compile warnings if that function is actually used at compile time.

like image 56
MSN Avatar answered Oct 14 '22 11:10

MSN