cpp-partial -- preprocessor directive partial evaluator

This is a Perl script that partially evaluates the #ifdef/#ifndef preprocessor directives in a file, stripping out whatever code it can given the information available. This allows you to take code from a big project with loads of #ifdefs in it, and 'specialize' it into something a lot smaller and more workable by saying "these macros are defined, these macros are undefined, but leave everything else as it is".

This tool can also be used as an aid when getting to understand the code of a new project on meeting it for the first time. Often the sense of the code is hidden by the mass of #ifdefs through it. Taking a sample configuration of #defines and stripping out all other code can make it all a lot more understandable, after which you can return to the original code with some sense of what is going on.


The 20060402 version makes in-place file modification an option instead of the default, and adds an option to output to STDOUT instead of to files. The 20040226 version fixes a logic error when handling nested #else; thanks to David Day for pointing this out.

  cpp-partial-20060402.tgz (2K)
  cpp-partial-20040226.tgz (2K)
  cpp-partial-20031124.tgz (2K)

UAZU-Up- These pages and files, including applets and artwork, are Copyright (c) 1997-2016 Jim Peters unless otherwise stated. Please contact me if you'd like to use anything not explicitly released, or if you have something interesting to discuss.