1

I am using the newest Visual Studio 2022 and also installed the Intel C++ compiler.

When I just write a simple main() to print the values of the macros MSC_VER and __INTEL_LLVM_COMPILER, I get

  • MSC_VER = 1937, and
  • __INTEL_LLVM_COMPILER = 20230200.

How is it possible that both have values defined? I must be using the wrong macros, so what's the right macro to check?

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
ijklr
  • 145
  • 8

1 Answers1

2

Compilers that aim for compatibility with MSVC typically define _MSC_VER. Similar to how compilers that support the GNU dialect of C define __GNUC__ to a version number: How to tell Clang to stop pretending to be other compilers?

True MSVC will definitely not define __INTEL_LLVM_COMPILER or __llvm__, so

#if defined(_MSC_VER) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
  // real MSVC, or a different non-LLVM-based compiler emulating it.
#else
...
#endif

Checking for __llvm__ should be good to exclude mainline Clang and clang-cl as well as Intel's LLVM-based ICX / ICPX and/or OneAPI stuff.

__INTEL_COMPILER is defined by Intel's "classic" (non-LLVM) compilers, ICC (C) and ICPC (C++).

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Are you right, I was on Intel C++ compiler as it turned out. Once I switched back to MSVC, __INTEL_LLVM_COMPILER is not defined. – ijklr Aug 31 '23 at 00:54