How do I run the GCC preprocessor to get the code after macros like #define are expanded?

后端 未结 3 839
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 06:11

Is there an option that the GCC preprocessor could generate C source code and filter out irrelevant source code?

For example, a .c file has a #def

相关标签:
3条回答
  • 2020-11-27 06:41

    While the -E option will perform all pre-processing, it also produces some very 'raw' output that might not be what you want (depending on what you want).

    If you need to debug a macro expansion that's not doing what you expect, E is a good way to go. If you simply want to filter out the 'inactive code', but leave the remaining code in more-or-less original form, you might want to look at the answers to the following Stack Overflow question:

    • Is there a C pre-processor which eliminates #ifdef blocks based on values defined/undefined?
    0 讨论(0)
  • 2020-11-27 06:41

    It sounds like you want unifdef, not the GCC preprocessor.

    0 讨论(0)
  • 2020-11-27 06:52

    Yes. Use the -E option:

    gcc -E foo.c
    
    0 讨论(0)
提交回复
热议问题