Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What predefined macro can I use to detect clang?

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 ?

like image 708
Pierre Bourdon Avatar asked Sep 27 '22 12:09

Pierre Bourdon


People also ask

How do you check Clang?

Open a terminal window. Enter the command (clang — version) to confirm if the Clang Compilers had already been installed.

Does Clang define __ GNUC __?

(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.

What is __ GNUC __?

__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 .

Is Clang the same as G ++?

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.


1 Answers

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.

like image 129
Chris Suter Avatar answered Oct 13 '22 05:10

Chris Suter