开发者

Any script to strip out the compiled source in C++

开发者 https://www.devze.com 2023-04-12 05:18 出处:网络
In my C++ file, I have #ifdef DEBUG then blah #else blooh. I want to strip out all text that does not get compiled after preprocessing, so that if DEBUG is not defined, then all statement of th

In my C++ file, I have

#ifdef DEBUG 
    then blah
#else 
    blooh. 

I want to strip out all text that does not get compiled after preprocessing, so that if DEBUG is not defined, then all statement of the form:

#ifdef DBU开发者_如何学GoG 
    /* some debug code */ 
#endif

gets stripped out of the source.

EDIT: Here is an example :

#include <iostream>
//#define DEBUG
int main(){
  #ifdef DEBUG
      cout << "In debug\n";
  #endif
     cout << "hello\n";
  return 0;
 }

And after running the script , the output should be

#include <iostream>
//#define DEBUG
int main(){
  cout << "hello\n";
 return 0;
}


Is just running the preprocessor not good enough? For example g++ -E?


Just run your compiler's preprocessor with the appropriate defines. On Windows, this would be cl /EP file and on Linux gcc -E. Most likely, you'll have to pass your defines as well, using -DFoo.


I don't know the answer to your question, but Google does:

  • A Partial Preprocessor for C
  • cpp-partial -- preprocessor directive partial evaluator


The preprocessor does this.

You can use g++ -E somefile.cpp to see what it generates.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号