tags:

views:

286

answers:

1

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.

+2  A: 

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.

Dipstick
So I suppose the runtime conversion is the only way?
CommanderZ
So I did it the runtime way. Thanks for answer.
CommanderZ