Pergunta

When I do a Release build of my Visual Studio 2008 solution I get a bunch of errors like this:

error C2059: syntax error : ','

This is how I typically use TRACE:

TRACE(_T("My error message.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);

There is also an instance where I use it with 5 parameters.

I thought TRACE was suppose to compile out completely for Release builds. What do I need to do to make it compile out complete? Thanks.

Foi útil?

Solução

The definition of your __WFILE__ macro is causing the problem. There are two ways to solve this. First, you can define the macro as shown here:

http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx

Note they don’t wrap the macro in #ifdef _DEBUG, which makes sense since the corresponding __FILE__ macro is not removed in release mode either.

But that documentation is for VS2005. It’s been removed from newer versions of the documentation. That’s why you may want to do this:

_T(__FILE__)

Outras dicas

First of all, it's __FILE__ as far as I know, not __WFILE__. that is why you get that comma error. Since preprocessor is unable to find it.

Second, why do you write the last three parameters in each TRACE? TRACE is a MACRO, right?

So you can define it like this: (also see the define __WFILE__ macro)

#define FULL_TRACE   //define FULL_TRACE here
#define __WFILE__  L##__FILE__ //since __WFILE__ is not a real macro in MCVC++
#define TRACE(msg) FULL_TRACE(msg, ::GetLastError(), __WFILE__, __FUNCTION__, __LINE__)

Now, you can TRACE like this

TRACE("Error in I/O file")

And you're done!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top