What predefined macro can I use to detect clang?

Pierre Bourdon picture Pierre Bourdon · Apr 17, 2010 · Viewed 32.8k times · Source

I'm trying to detect the compiler used to compile my source code. I can easily find predefined macros to check for MSVC or GCC (see http://predef.sourceforge.net/ for example), but I cannot find any macro to check for clang.

Does someone know if clang defines a macro like __CLANG__ in order to know what is currently compiling my code ?

Answer

Chris Suter picture Chris Suter · Apr 29, 2011

To get a list of all the predefined macros that the compiler uses, use this:

clang -dM -E -x c /dev/null

You can do the same for gcc.