Joe
Joe

Reputation: 655

Expanding macros for debugging?

I'm new to using macro functions and I understand there are some pitfalls in their use when it comes to order of operations. Is there a way to expand the macro after the preprocessor goes through it so I can see what it looks like?

In VS2017, I've tried Processor > C/C++ > Preprocessor > Preprocess to a file which creates an *.i file but it's around 50k lines long and I can't seem to find where my macro was expanded to.

edit: I know macros are bad news bears, however, the code base I'm stepping into uses them quite a bit so I'm trying to better understand them.

Upvotes: 0

Views: 1389

Answers (1)

R Sahu
R Sahu

Reputation: 206697

In VS2017, I've tried Processor > C/C++ > Preprocessor > Preprocess to a file which creates an *.i file but it's around 50k lines long and I can't seem to find where my macro was expanded to.

You can help yourself by declaring a dummy variable before the line where a macro is used.

E.g.

extern int dummyIntVariable;
MY_COMPLICATED_MACRO(arg1, arg2);

After that, you look for dummyIntVariable in the .i file. The line below it will contain what MY_COMPLICATED_MACRO expands to.

Or as @Sneftel pointed out in a comment, you can use any old string that helps you navigate through the .i file.

THIS IS A UNIQUE STRING
MY_COMPLICATED_MACRO(arg1, arg2);

Since the file will be just pre-processed, that should also work.

Upvotes: 3

Related Questions