Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wide version of __FUNCTION__ on linux

Tags:

widechar

is there a way i can print __FUNCTION__ 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

like image 402
sramij Avatar asked Nov 26 '22 12:11

sramij


1 Answers

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.
like image 99
CristiFati Avatar answered Nov 29 '22 00:11

CristiFati