Posts Tagged clang

Detecting GCC vs. Clang/LLVM

The crux of the matter is that Clang also defines the __GNUC__ macros, which took me an hour or so to debug. So if you need a GCC vs. Clang (vs. LLVM-GCC) switch, you _must_ check for Clang/LLVM first.


#if defined __clang__ /* The Clang frontend to LLVM (Clang) */
#define COMPILER "Clang"
#elif defined __llvm__ /* The GCC frontend to LLVM (LLVM-GCC) */
#define COMPILER "LLVM-GCC"
#elif defined __GNUC__ /* The GNU GCC compiler */
#define COMPILER "GCC"
#else
#define COMPILER "Unknown"
#endif

Note: Code is public domain, use it freely.

, , , ,

No Comments