views:

1156

answers:

3

I'm working on getting a Visual C++ 2005 solution to compile in unicode. However, In some of my projects (but not all), I get errors in the form:

1>.\CBitFlags.cpp(25) : error C2065: 'L' : undeclared identifier

and the line of code in question is:

LOGERROR(UTILITY, L"Tried to use object to store %d flags, when max is %d",

I am BAFFLED. It seems to be treating L as an identifier when L is part of the language syntax. Does anyone know if there is some flag somewhere that has to be enabled in the project or compile settings that if not toggled would cause this? The really weird part is it isn't all of the occurrences of this, it's only some of them. It does seem to be consistent within a single project, but I have entire projects compiling fine, and others that fail miserably like this.

A: 

Since this appears to be something used in a macro, I think you should look at the definition of the LOGERROR and UTILITY macros and at what they expands to in the context of your code. Use the /P compiler option to preprocess your files without proceeding to the compilation step, and then look at the result to see what the compiler's really seeing.

I can reproduce the error you see if I have a space after the L:

wchar_t const* foo = L "foo";

Are you sure you've copied and pasted the actual code that's giving you trouble?

Rob Kennedy
+1  A: 

The problem is almost certainly inside of the LOGERROR macro. Look at how it treats that second paramater. Expand the macro yourself, it is easy to overlook small errors in macros sometimes.

Ed Swangren
Bingo. LOGERROR was actually using __FILE__ to get the filename and trying to convert that to a widechar literal using other macros, and that's where the error was cropping up, not in the actually string being passed to LOGERROR.
__matt__
A: 

Visual C++ 2005 does support the L syntax for wide strings, and doesn't need any special flags or anything to support it. So most likely, your problem is elsewhere. Perhaps the definition of LOGERROR or UTILITY. Or a missing semicolon previously, or.... It could be anything which causes the compiler to expect something other than a string literal when it gets to the L.

jalf