Derik
Derik

Reputation: 57

How to see (or check) values of macro function in C during debugging mode in MS visual studio?

I would like to check a numerical value evaluated by a function macro in C during debugging mode. I defined a function as macro like below.

#define H_H2(T)        0.2584e4*exp(170/(T))

When I tried to evaluate this function H_H2(298) during debugging mode at watch window in Visual studio, it generated an error identifier "H_H2" is undefined.

Could someone let me know how to evaluate a macro function during debugging mode ?

Upvotes: 1

Views: 1449

Answers (2)

0___________
0___________

Reputation: 67749

It is not possible in the VisualStudio if you use Microsft debugger. But you can debug it if you use gdb and gcc compiler. It is possible if you debug WSL application in the VS https://learn.microsoft.com/en-us/cpp/linux/deploy-run-and-debug-your-linux-project?view=msvc-160.

When you compiler using gcc family debuggers and use gdb you can easily see and evaluate macro definitions by adding the -g3 compiler option.

From gcc documentation:

Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.

Upvotes: 0

PaulProgrammer
PaulProgrammer

Reputation: 17670

You can't. Macros are resolved during the preprocessor, and as a result they don't exist in compiled code.

If you need to debug such an expression, create a function, or step through the disassembled code (Ctrl+,G in VS2019).

Upvotes: 3

Related Questions