开发者

wide version of __FUNCTION__ on linux

is there a way i can print __FUNCTION__开发者_Python百科 as a wide character on linux?

the trick with the WIDEN doesn't work for me, the gcc compiler prints: error: ?L_FUNCTION_? was not declared in this scope

any help? Thanks


7+ years later (although things seem to be the same) ...

Since you mentioned gcc, check [GNU.GCC]: Standard Predefined Macros (emphasis is mine):

C99 introduced __func__, and GCC has provided __FUNCTION__ for a long time. Both of these are strings containing the name of the current function (there are slight semantic differences; see the GCC manual). Neither of them is a macro; the preprocessor does not know the name of the current function.

Since __FUNCTION__ is not a macro (the preprocessor doesn't "know" anything about it), it will remain untouched during (outer) macro expansion, generating at the end the L__FUNCTION__ identifier, which is obviously invalid.
That's why the double macro approach works for __FILE__ (for example), but not for __FUNCTION__ (or __func__).

So, the short answer to your question is "NO" (at least not at preprocessor level). You will need to convert __FUNCTION__ "manually" (e.g. using one of the [man7]: MBSTOWCS(3) functions family).

Note: It works on VStudio, since according to [MS.Docs]: Predefined Macros (emphasis still mine):

  • __FUNCTION__ Defined as a string literal that contains the undecorated name of the enclosing function. The macro is defined only within a function.


It can be done using macros, you just have to understand how macros expand. To get a wide char version of the macro you need to create 2 layers of macros like so:

#define WIDE2(x) L##x
#define WIDECHAR(x) WIDE2(x)

#define WIDE_FUNCTION WIDECHAR(__FUNCTION__)

The all important piece is the L##x that appends the L character to the string constant before the compiler sees it. You can do this to __FILE__ as well using the same technique.


That looks more like a typo of __FUNCTION__ than an issue with widen() or similar, at least if you pasted the exact error message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜