2

I am looking to expand only macros in my C++ code. I understand that -E option runs only preprocessor, but I am not looking for complete preprocessed output. All I want is a C++ code with all macros expanded.

I need to submit this code to a analyser, who don't understand macros. But a preprocessed code will defeat the purpose, as it will add lot of third party code (via include files) to the code.

6
  • Why exactly can't you use the -E switch? Or use cpp src_file. Commented Oct 29, 2015 at 8:59
  • 2
    Possible duplicate of Run a "light" preprocessor for GCC Commented Oct 29, 2015 at 9:08
  • I had same issue and never found a solution, right now I delegated most of the work of Macros to a external tool (Cmake) so that I have minimal macro that don't really need expansion to get debugged. your best bet is having code where include files are really mimimal (in example using Pimpl idiom or pure virtual classes greatly reduces number of inclusions). I think certain IDES just show expanded macro if you put mouse over it Commented Oct 29, 2015 at 9:08
  • @cad That would strip comments and evaluate all #include and #if directives as well. Commented Oct 29, 2015 at 9:08
  • Do you need to keep #ifdefs too? Commented Oct 29, 2015 at 9:09

1 Answer 1

0

If you just want macro expansions and skip the #include handling, this may help: https://github.com/ned14/pcpp/pull/34

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.