C - used and unused constants in header files, how to resolve?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C - used and unused constants in header files, how to resolve?

5,269 Views
blewis
Contributor I
Can anyone recommend the best way to find dead constant defines in a header that is included into a module, and or the constants that are used?

Over time I have added defines to header files and would like to clean up the headers now, but it is an overwhelming task. There are many headers and some have a few constants that are needed and many that are not. Short of commenting out the lines and compiling, or doing a search through each file with the definition I can not see a good way to do this. Does anyone know of a software tool that would list all constants used versus dead constants in a module. Or is there a way to do this in CW? We have the professional version of CW.

Thanks inadvance

Robert
Labels (1)
0 Kudos
4 Replies

690 Views
CrasyCat
Specialist III
Hello
 
A couple of questions here to better understand what you are trying to achieve here.
.
Which processor are you targeting (HC08, HC12, Coldfire, ...)?
Are you trying to find unused macros (defined with #define) or unused constants (defined with const)?
 
Macros do not use any memory on the final application image. So I am not sure why you would look for unused macros.
 
CrasyCat
0 Kudos

690 Views
blewis
Contributor I
I am trying to find unused macros or anything actually that was unused. I agree they doesn't take up memory, but as with anything that expands over time, extraneous and dead defines can be a potential problem.

#define symbl1 0x10 then later
#define symbol1 0x01, and the wrong definition can be used and so on. It has has been my experience that it is better to try and keep the code as uptodate as possible.

I will try the program listed above and see if that is a solution.

Thank you to everyone for the advice.

Best Regards

Robert Lewis
0 Kudos

690 Views
Alban
Senior Contributor II
Hello Robert,

I see a potential problem with that.
The pre-processor is using #DEFINE declarations for conditional compilation.

But I see an option where you could use a PERL script (or anything similar) that would check if the defined name has another occurrenc in the project files.

What do you think ?
Cheers,
Alban.
0 Kudos

690 Views
pittbull
Contributor III
Hi,
There's a nice tool that can analyze your codes, finds unused macros, functions and so on.
--> http://www.scitools.com/products/understand/cpp/product.php
You can download a full working but time-limited version...
 
0 Kudos