c++ - GCC、Unicode 和 __FUNCTION__

标签 c++ gcc unicode

我正在尝试让我的项目在 GCC 下编译(Visual Studio 可以完美地编译它)。

我有一个自定义断言函数,它会抛出一条 wstring 消息。它的一部分是 _ _FUNCTION__ 宏,我使用 MSDN 中的 WIDEN 宏将其“统一编码”

#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)

它在 MSVC 中编译正常,但在 GCC 中打印如下:

error: ‘L__FUNCTION__’ was not declared in this scope

我能想到的唯一解决方案是在运行时使用 mbstowcs 将 __FUNCTION __ 的内容转换为 wstring,但我想找到一种编译时方法来完成它。

感谢您的帮助。

最佳答案

在 GCC 中 __FUNCTION__ 是一个非标准扩展。引用:GCC Online Docs

In GCC 3.3 and earlier, in C only, __FUNCTION__ and __PRETTY_FUNCTION__ were treated as string literals; they could be used to initialize char arrays, and they could be concatenated with other string literals. GCC 3.4 and later treat them as variables, like __func__. In C++, __FUNCTION__ and __PRETTY_FUNCTION__ have always been variables.

所以在 __FUNCTION__ 前面添加 L 只会将其变成 L__FUNCTION__,这可能是未定义的。

关于c++ - GCC、Unicode 和 __FUNCTION__,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2518969/

相关文章:

c++ - 在 Windows Vista 上将 MSADO15.DLL 和 C++ 与 MinGW/GCC 结合使用

linux - 摆脱 "gcc -/usr/bin/ld: warning lib not found"

c - "Variably modified ' 变量名 ' at file scope"大小在宏中定义

使用 memcmp() 和指针算法比较 C 中的结构

c# - 是否可以将 unicode hex\u0092 显示(转换?)为 .NET 中的 unicode html 实体?

javascript - 允许所有字母字符加上 unicode 字符的正则表达式

c++ - 如何开始编写智能指针?

c++ - 在 c++/c# 中替代 drools-planner/optaplanner?

c++ - zsh/sh/bash 如何检查从 C++ 程序启动的命令 "cat &"的信号 SIGTTIN

Python "denormalize"unicode 组合字符