check unused variable in C project

Viewed 2040

I developed new C project and I use some time variables to debug or to check value ...

I want to be sure if I don't forget any unused variable after achieving project.

there is a Linux utilities or command to do that ?

4 Answers

Some compilers can issue a warning for you when an automatic variable is unused. Try

gcc -Wunused-variable
clang -Wunused-variable

I would do such things with preprocessor statements.

For example, you could define: #define DEBUG

and in code

#ifdef DEBUG

//debug code in here

#endif

When compiling the final code, just don't define DEBUG

use macros in your debug instead of using variable directelly. this is more proper

I recommend you use cppcheck, it comes in ubuntu repositories or you can download and compile the code from:

cppcheck

It's an awesome tool of static code analysis that will tell you some of the code errors you can make.

Related