Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool/Parser for preprocessor #if statements?

I am working on many C-sourcecode files which contain many preprocessor #if, #elseif and #else statements.

This statements often check for a #define, e.g.

#if(Switch_TestMode == Switch_TestModeON)
/* code 1 */
#else
/*code 2 */
#endif

Often this preprocessor statements are located within c-if statements which makes the sourcecode nearly unreadable for human beeings.

The #defines used for this preprocessor #if statements are defined within an extra file.

My idea now is to have a tool which checks this #defined switch settings and then only copies the lines of sourcecode which apply using the current #defines/switch settings.

For the above example I would like to get a new .c file which contains only

/*code 2 */

assumed the #define of Switch_TestMode is not equal to Switch_TestModeON.

Are there tools (freeware || low-cost) available which do this job? Or do I have to write my own preprocessor parser for this?

(It is impossible for me to run the compiler using a special parameter which does this job, because our company is creating the C-sourcecode, another company is compiling.)

Thanks for any hint!

Regards

Thomas

like image 295
Thomas Schuster Avatar asked Nov 03 '10 23:11

Thomas Schuster


2 Answers

unifdef is available from http://dotat.at/prog/unifdef/.

like image 187
Tony Finch Avatar answered Oct 02 '22 19:10

Tony Finch


Try Sunifdef

Edit: Which has now become Coan

like image 43
doron Avatar answered Oct 02 '22 19:10

doron