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.
The identifier __PRETTY_FUNCTION__ holds the name of the function pretty printed in a language specific fashion. These names are always the same in a C function, but in a C++ function they may be different. For example, this program: extern "C" { extern int printf (char *, ...
Macros can be undefined from the command line using the /U option, followed by the macro names to be undefined.
4. Which gcc option undefines a preprocessor macro? Explanation: None.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With