Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Does Intel Compiler use both of __INTEL_COMPILER and __GNUC__ at the same time?

jerryleo
Beginner
2,255 Views
Folloing codes will get warning #47: incompatible redefinition of macro and detected the compiler as GCC while compiling by icc.

#ifdef __INTEL_COMPILER
#define compiler "Intel"
#endif

#ifdef __GNUC__
#define compiler "GCC"
#endif

How can I detect Intel compiler by using the pre-defined compiler macros?

Thanks

Jerry
0 Kudos
1 Solution
TimP
Honored Contributor III
2,255 Views

Perhaps OP wanted something like the often used:

#if defined __INTEL_COMPILER
#define COMPILER "Intel"
#elif defined __GNUC__
#define COMPILER "GCC"
#endif

or

#ifdef __INTEL_COMPILER
#define compiler "Intel"
#endif

#if defined __GNUC__
#if defined __INTEL_COMPILER
#error "not supporting Intel gcc-compatible (e.g. linux) compilers"
#endif
#define compiler "GCC"
#endif

View solution in original post

0 Kudos
4 Replies
TimP
Honored Contributor III
2,255 Views
How about putting the #ifdef __GNUC__ in a #else section, if that's what you want?
__GNUC__ has to be defined in order for header files which use it to work with icc.
0 Kudos
Vladimir_P_1234567890
2,255 Views
It is not 100% clear for me what TimP wrote:) so i'm re-wrtiting example
[cpp]#ifdef __INTEL_COMPILER
#define compiler "Intel"
#else
#define compiler "GCC"
#endif[/cpp]
--Vladimir
0 Kudos
TimP
Honored Contributor III
2,256 Views

Perhaps OP wanted something like the often used:

#if defined __INTEL_COMPILER
#define COMPILER "Intel"
#elif defined __GNUC__
#define COMPILER "GCC"
#endif

or

#ifdef __INTEL_COMPILER
#define compiler "Intel"
#endif

#if defined __GNUC__
#if defined __INTEL_COMPILER
#error "not supporting Intel gcc-compatible (e.g. linux) compilers"
#endif
#define compiler "GCC"
#endif

0 Kudos
jerryleo
Beginner
2,255 Views
Thanks for all kindly help

Jerry
0 Kudos
Reply