"Undeclared identifier" error in simple macro expansion

I have a very simple macro that I use to shortcut when declaring exceptions. In debug mode, it adds the current file and line number.

I am in the process of changing my code to maintain unicode, and suddenly I get "undeclared identifier" errors whenever my macro is used. I probably missed something very simple as the macro itself is pretty simple. Can anyone tell me what the problem is?

Here's the macro declaration:

#ifdef _DEBUG
#define EXCEPTION(msg, mm) Exception(msg, mm, _T(__FILE__), _T(__LINE__))
#else
#define EXCEPTION(msg, mm) Exception(msg, mm)
#endif

      

I don't think it's necessary, but just in case, here's the declaration for the exception constructor:

Exception(LPCTSTR msg, BOOL manageMsg = FALSE, LPCTSTR f = NULL, int l = -1);

      

When compiling in release mode, I don't get any errors, but when in debug mode I do it, so it's something with the __FILE__ and __LINE__ bits, but I can't figure out what the real problem is.

0


a source to share


2 answers


The macro __LINE__

evaluates to an integer. The macro _T

puts L

at the beginning of lines to make them Unicode strings. It was followed by a double opening quote, for example L"file.cpp"

. But in your case, this was accompanied by an integer literal that __LINE__

expands. You get something like this: L23

. Get rid of the second call _T

.

#define EXCEPTION(msg, mm) Exception(msg, mm, _T(__FILE__), __LINE__)

      



It may be easier to diagnose if you supplied the name of an identifier that the compiler did not recognize. Compilers usually include this information in their error messages.

+3


a source


This was not exactly the same problem as mine, but I am posting a solution to my problem here because I ran into this question during my research.

If you encounter this error message with a multi-line macro, include visible spaces in your editor. You may have a space after the continuation character '\' at the end of the line:



#define FOO_BAR(aFoo) \ 
    FOO_BASE(aFoo, "bar")

      

The space at the end causes the parser to parse the first line of the macro definition as terminated (FOO_BAR expands to '\'), and the second line is interpreted as a function declaration, therefore "undeclared identifier" aFoo ").

+2


a source







All Articles