highsciguy
highsciguy

Reputation: 2647

How to detect Intel's compiler (ICC) with ifdef?

I want to use Intel's current compiler on Linux. I have an inline macro which is supposed to detect the compiler.

It used to work with past versions of GCC and ICC. But now I get extern inline with ICC. Does ICC now define __GNUC__? How would you detect ICC or Intel's C++ compiler, ICPC?

#ifndef INLINE
# if defined(__GNUC__) || defined(__GNUG__)
#  define INLINE extern inline
# else
#  define INLINE inline
# endif
#endif

Upvotes: 8

Views: 5153

Answers (2)

Laci
Laci

Reputation: 2818

The following webpage shows information about how to detect recent Intel compilers:

https://software.intel.com/content/www/us/en/develop/articles/use-predefined-macros-for-specific-code-for-intel-dpcpp-compiler-intel-cpp-compiler-intel-cpp-compiler-classic.html

EDIT (here is the code from the website to differentiate between different versions):

// Predefined macros Intel® DPC++ Compiler
// dpcpp only
#if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)
   // code specific for DPC++ compiler below
   // ... ...

  // example only
   std::cout << "SYCL_LANGUAGE_VERSION: " << SYCL_LANGUAGE_VERSION <<  std::endl;
   std::cout << "__INTEL_LLVM_COMPILER: " << __INTEL_LLVM_COMPILER << std::endl;
   std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif


 //Predefined Macros for Intel® C++ Compiler
#if !defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)
   // code specific for Intel C++ Compiler below
   // ... ...

   // example only
   std::cout << "__INTEL_LLVM_COMPILER: " << __INTEL_LLVM_COMPILER << std::endl;
   std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif

// Predefined Macros for Intel® C++ Compiler Classic
// icc/icpc classic only
#if defined(__INTEL_COMPILER)
   // code specific for Intel C++ Compiler Classic below
   // ... ...

   // example only
   std::cout << "__INTEL_COMPILER_BUILD_DATE: " <<   _INTEL_COMPILER_BUILD_DATE << std::endl;
   std::cout << "__INTEL_COMPILER: " << __INTEL_COMPILER << std::endl;
  std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif 

Upvotes: 2

Mahmoud Al-Qudsi
Mahmoud Al-Qudsi

Reputation: 29579

__INTEL_COMPILER is what you are looking for. (Source: ICC man page)

Upvotes: 15

Related Questions