stringizing __LINE__ in Visual C++ 2003

Anyone know how to get around the problem with stringizing __LINE__ in Visual C++ 2003 when /ZI (Program Database for Edit & Continue) is used?

I'd rather not have to switch to /Zi (Program Database) and lose Edit & Continue.

For example:


#define _STR2_(x) #x
#define _STR1_(x) _STR2_(x)
TRACE(_STR1_(__LINE__));


Instead of a numeric value I get "(__LINE__Var+1)".

[863 byte] By [PeterRitchie] at [2007-12-17]
# 1
Hi Peter:

With VS2005, I tried dropping your macros into an mfc dialog based app (ONOK handler) as follows:


#define _STR2_(x) #x

#define _STR1_(x) _STR2_(x)

void CmfcfooDlg::OnBnClickedOk()

{

TRACE(_STR1_(__LINE__));

TRACE("\n");

OnOK();

}


And the debugger shows me the line number as expected. Do you have a small repro you could share? My email address shows in the profile.

RickTroemelMS at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 2
Hi Again Peter:

I read your post more closely and realized you are using VS2003 and are likely referring to the bug in the KB article at http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b199057.

The good news is that the problem is corrected in VS2005, the bad is that there is no other workaround besides switching to /Zi.

One suggestion I could make - if you are using __LINE__ to generate a unique identifier, __COUNTER__ may work for you.

Hope This Helps,

RickTroemelMS at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 3
Hi Rick. Thanks for your posts; but, my original post mentioned that I would like to not have to use /Zi as suggested in 199057.

One of my uses for __LINE__ is to generate trace output that can be double-clicked in the Visual Studio output window to jump to the appropriate source file/line number. __COUNTER__ won't work in this case.

PeterRitchie at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ Language...