How can I detect g++ and MinGW in C++ preprocessor?

EddieV223 picture EddieV223 · Jul 5, 2013 · Viewed 28.5k times · Source

I want to do something like:

#ifdef GCC
#define GetFunctionName() string("My function name is ") + __PRETTY_FUNCTION__;
#endif

Since I want to use pretty PRETTY_FUNCTION this is only supported by gnu as far as I know so I need to detect if I am compiling for g++ and MinGW, how can I do that? I'm guessing all I need to know are the compiler's preprocessor definitions, like I did for Microsoft below.

#ifdef WIN32
#define LogFuncBegin() gLogger.FuncBegin( __FUNCTION__ );
#define LogFuncEndSuccess() gLogger.FuncEndSuccess( __FUNCTION__ );
#endif

How can I detect g++ and MinGW in C++ preprocessor?

Answer

Floris Velleman picture Floris Velleman · Jul 5, 2013

You can make use of:

#ifdef __GNUC__
#ifdef __MINGW32__

For additional macro's you might be interested in this page which shows other compiler macros