How to debug macros efficiently in VS?

前端 未结 9 1744
情书的邮戳
情书的邮戳 2021-02-01 22:38

I\'ve got a pretty complicated macro inside my (unmanaged) C++ code. Is there any way to expand macros in VS debugger? Or maybe there is another way to debug macros there?

9条回答
  •  -上瘾入骨i
    2021-02-01 22:55

    I heard all possible negative answers on the topic:

    • macros can only be expanded not evaluated
    • preprocessor should parse also include files
    • nested macros can be over-complicated
    • conditional preprocessing can be tricky
    • macros are evil just avoid them
    • etc etc....

    They are all true, but IMO they collide with the reality of everydays programming.

    In fact, working on old C project, where macros were mostly simply used as functions, this became of crucial importance for me. Generating all preprocessed files with /P works, but is overkilling and time consuming. I just needed a tool that expands a simple macro defined a few lines above or at maximum in other file.

    How to do that?

    1. On Linux simply use GDB and his expand macros capabilities
    2. On windows I use https://www.jetbrains.com/resharper-cpp/ integrated into Visual Studio

    So, Yes, in a practical sense, it is possible.

提交回复
热议问题