Tool/Parser for preprocessor #if statements?

折月煮酒 提交于 2019-12-04 11:39:01

问题


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


回答1:


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




回答2:


Try Sunifdef

Edit: Which has now become Coan




回答3:


You can run the GNU compiler using command line option -E to do the preprocessing.

http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html




回答4:


You can use unifdef.



来源:https://stackoverflow.com/questions/4092430/tool-parser-for-preprocessor-if-statements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!