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 #define
s used for this preprocessor #if
statements are defined within an extra file.
My idea now is to have a tool which checks this #define
d 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, b开发者_开发知识库ecause our company is creating the C-sourcecode, another company is compiling.)
Thanks for any hint!
Regards
Thomas
unifdef is available from http://dotat.at/prog/unifdef/.
Try Sunifdef
Edit: Which has now become Coan
You can run the GNU compiler using command line option -E to do the preprocessing.
http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html
You can use unifdef.
精彩评论