Seeing expanded C macros

后端 未结 12 957
清歌不尽
清歌不尽 2020-11-28 05:31

If I want to expand a C macro, what are some good ways to do that (besides tracing it manually)?

For instance, GTK_WIDGET_SET_FLAGS, it uses a macro that

相关标签:
12条回答
  • 2020-11-28 05:46

    In Visual Studio, you can generate the preprocessor resulted translation unit file. You can go project options, C/C++/Preprocessor and put "Generate Preprocessed File" or "Preprocess to a File" on Yes (or use /P or /EP compiler switch to include line numbers or not).

    0 讨论(0)
  • 2020-11-28 05:49

    gcc even with -E needs the path of the header files ... like -I _path_to_your_headers...

    If you've a Makefile, generally, what you could do is over-riding CC with gcc -E

    Generally, cpp is only a script adding some flags to gcc for the preprocessor, like traditional...

    0 讨论(0)
  • 2020-11-28 05:51

    Try running cpp on your source file

    0 讨论(0)
  • 2020-11-28 05:55
    gcc -E myfile.c
    
    0 讨论(0)
  • 2020-11-28 05:56

    Have you tried running gcc -E multiple times until there are no longer any macros?

    0 讨论(0)
  • 2020-11-28 05:57

    When trapped in a sketchy IDE, try something like

    #define DISPLAY_VALUE2(x) #x
    #define DISPLAY_VALUE(x) DISPLAY_VALUE2(x)
    #pragma message("#DEFINE F_CPU " DISPLAY_VALUE(F_CPU))
    

    to produce

    …/sketch_may21a.ino: In function 'void loop()':
    …/sketch_may21a.ino:10:54: note: #pragma message: #DEFINE F_CPU 16000000L
    #pragma message("#DEFINE F_CPU " DISPLAY_VALUE(F_CPU))
                                                         ^
    

    thanks to "mdematos" at http://MicroChip.com/forums/m724722.aspx

    0 讨论(0)
提交回复
热议问题