有什么方法可以打印__FUNCTION__
作为 linux 上的宽字符?
WIDEN 的技巧对我不起作用,gcc 编译器打印:
错误:?L_FUNCTION_?在这方面没有申明
有什么帮助吗?
谢谢
最佳答案
7 年后(虽然事情似乎是一样的)......
既然你提到了 gcc,检查 [GNU.GCC]: Standard Predefined Macros ( 重点 是我的):
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.
自 __功能__ 不是宏(预处理器不“知道”任何关于它的信息),它在(外部)宏扩展期间将保持不变,最后生成
L__FUNCTION__
标识符,这显然是无效的。这就是为什么双宏方法适用于 __文件__ (例如),但不适用于 __功能__ (或 __func__ )。因此,对您的问题的简短回答是“ NO ”(至少 而不是 在预处理器级别)。您需要转换 __功能__ “手动”(例如,使用 [man7]: MBSTOWCS(3) 函数系列之一)。
备注 :它适用于 VStudio,因为根据 [MS.Docs]: Predefined Macros ( 重点 仍然是我的):
- __FUNCTION__ Defined as a string literal that contains the undecorated name of the enclosing function. The macro is defined only within a function.
关于widechar - Linux 上 __FUNCTION__ 的宽版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4773941/