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 ?
Open a terminal window. Enter the command (clang — version) to confirm if the Clang Compilers had already been installed.
(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.
__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ These macros are defined by all GNU compilers that use the C preprocessor: C, C++, Objective-C and Fortran. Their values are the major version, minor version, and patch level of the compiler, as integer constants. For example, GCC version x . y .
Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.
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.
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