I'm searching for a preprocessor which allows for partial preprocessing of C source files. What I want to do is to skip certain or all #include and to define some macros on the command line (or a separate file), the preprocessor then should only process what I specified and ignore the rest.
Here is an example of what I want to do:
#define FOO
#ifdef FOO
/* FOO */
#endif
#ifdef BAR
/* BAR */
#endif
should be translated into
/* FOO */
#ifdef BAR
/* BAR */
#endif
Some time ago at my previous job I needed a similar preprocessor and I think that I found a link to a standalone preprocessor here on stackoverflow, however after an hour of searching the web I gave up.
You might be looking for coan
, which has the ability to interpret #if
and #ifdef
directives given a set of definition (or undefinitions) supplied on the command-line.
coan is based on the unifdef
utility listed in this related question: Partially processing a file with the preprocessor .
Also see Is there a C preprocessor that eliminates #ifdefs but also evaluates preprocessor macros? which has an example invocation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.