Search code examples
cconditional-compilation

C: How to conditionally compile certain parts of code based on Compiler Type?


I would like to conditionally compile certain parts of code based on Compiler Type is there any macro for that?

Like this:

#if defined (COMPILER_TYPE e.g. GCC)
// Compile this
#elif defined (COMPILER_TYPE e.g. Visual Studio C Compiler)
// Else this
#endif

Thank you


Solution

  • You can check if these macros are defined, __GNUC__ for GCC and _MSC_VER for MSVC.