Reputation: 6807
I have a Windows Phone 8 Solution with a Windows Runtime Component project. In the WinRT code I want to use __FUNCTION__
for logging from a C++ class.
However, __FUNCTION__
is not defined whereas __LINE__
is.
Intellisense only suggests __FUNCTIONW__
to use. But when I jump to the definition of __FUNCTIONW__
in crtdefs.h
I can see that __FUNCTION__
is not defined there either:
I have read Why would __FUNCTION__ be undefined? but that did not help me (or I did not understand the problem described there correctly)
How could __FUNCTION__
not be defined? I thought it is build in to the compiler...
Update:
OK, I learned that __FUNCTION__
is actually never colored. Yet I get an error when I type:
TCHAR* f = _T(__FUNCTION__);
It says:
Error: Identifier "L__FUNCTION__" is undefined
Maybe something is wrong with my UNICODE setup? Is there a special header that I need to include?
Upvotes: 0
Views: 799
Reputation: 941218
It works fine when I try it in a C++ Phone 8 app. Do note that you might be confuzzled by __FUNCTION__
not appearing in the IntelliSense auto-complete list. You can only see __FUNCTIONW__
. Which is a flaw, the macro is predefined in the compiler but that was overlooked for the IS parser. Since the definition of the macro doesn't appear anywhere in the included headers, the parser won't ever see a definition for it (like it does for __FUNCTIONW__
) and you'll see it missing from the list.
I can't confirm if this is a known bug, the search function at connect.microsoft.com isn't good enough to filter the 6600 hits that match "function". You can file the bug if you wish.
Update after edit: you are using the ancient TCHAR macros in your code. There's a trick to get the correct macro but I'm not going to document it. This all stopped being relevant well over 10 years ago when everybody stopped creating programs that could still run on one of the legacy Windows 9x versions. Certainly entirely pointless on a phone.
You in fact want to use __FUNCTIONW__
(without the _T
), it produces the Unicode string for the function name. It is a const wchar_t*.
Upvotes: 4