How to debug a macro

A

AS

Hello,
Can anybody tell me how to debug a macro ?

for ex,

#define PRINTSTRING() \


CString str = _T("hello"); \

AfxMessageBox(str); \
 
V

Victor Bazarov

AS said:
Can anybody tell me how to debug a macro ?

for ex,

#define PRINTSTRING() \


CString str = _T("hello"); \

AfxMessageBox(str); \

Most compilers support an option to output the result of
preprocessing. RTFM and see if yours does as well. Then
use your macro and see what it expands into.

V
 
I

Ian Collins

Victor said:
With all due respect, declarations cannot be rewritten as
inline functions.
Did you read the OP's example Victor? I assumed the question was asking
how to debug a function like macro. The only use I can see for function
like macros in C++ is as wrappers for functions when you want to pass
stringified tokens or macros in as parameters.

Something like

void printHere( const char* file, unsigned line, void* );

#define PRINT_HERE( x ) printHere( __FILE__, __LINE, (x) )
 
V

Victor Bazarov

Ian said:
Did you read the OP's example Victor?

Yes, I did. It contains a declaration.
I assumed the question was
asking how to debug a function like macro.

I assume nothing. That's the difference, I guess.
The only use I can see
for function like macros in C++ is as wrappers for functions when you
want to pass stringified tokens or macros in as parameters.

Something like

void printHere( const char* file, unsigned line, void* );

#define PRINT_HERE( x ) printHere( __FILE__, __LINE, (x) )

V
 
G

Gerhard Fiedler

Can anybody tell me how to debug a macro ?

I guess that depends on what exactly you want to debug.

If you want to debug the macro expansion, follow the advice of creating a
preprocessor output and analyse that.

If you want to debug the macro function, it sometimes is helpful to take
one macro instance, replace it with the expanded macro, and debug that
piece of code. When it works, replace it again with the (now working)
macro.

But, as someone else also already wrote, make sure you need a macro and
can't do it with an inline (or normal) function or other construct.

Gerhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top