Is there a C pre-processor which eliminates #ifdef blocks based on values defined/undefined?

南笙酒味 提交于 2019-11-26 04:32:34
Jörg W Mittag

I know absolutely nothing about C, but it sounds like you are looking for something like unifdef. Note that it hasn't been updated since 2000, but there is a successor called "Son of unifdef" (sunifdef).

I used unifdef years ago for just the sort of problem you describe, and it worked fine. Even if it hasn't been updated since 2000, the syntax of preprocessor ifdefs hasn't changed materially since then, so I expect it will still do what you want. I suppose there might be some compile problems, although the packages appear recent.

I've never used sunifdef, so I can't comment on it directly.

Also you can try this tool http://coan2.sourceforge.net/

something like this will remove ifdef blocks:

coan source -UYOUR_FLAG --filter c,h --recurse YourSourceTree

Around 2004 I wrote a tool that did exactly what you are looking for. I never got around to distributing the tool, but the code can be found here:

http://casey.dnsalias.org/exifdef-0.2.zip (that's a dsl link)

It's about 1.7k lines and implements enough of the C grammar to parse preprocessor statements, comments, and strings using bison and flex.

MSalters

If you need something similar to a preprocessor, the flexible solution is Wave (from boost). It's a library designed to build C-preprocessor-like tools (including such things as C++03 and C++0x preprocessors). As it's a library, you can hook into its input and output code.

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