开发者

GCC, Unicode and __FUNCTION__

I'm trying to make my project compile under GCC (Visual Studio compiles it flawlessly).

I have a custom assert function which throws a wstring message. A part of it is the _ _FUNCTION__ macro, which I "unicodize" using the WIDEN macro from MSDN

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

It compiles okay in MSVC, but it prints this in GCC:

error: ‘L__FUNCTION__’ was not declared in this scope

The only solution I could come with is to convert the contents of __FUNCTION __ to wstring on runtime using开发者_运维技巧 mbstowcs, but I would like to find a compile-time way to do it.

Thanks for help.


In GCC __FUNCTION__ is a non-standard extension. To quote: 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.

So adding L on the front of __FUNCTION__ is just going to turn it into L__FUNCTION__ which is probably undefined.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜