Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7677 Discussions

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

jerryleo
Beginner
1,336 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
Black Belt
1,336 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

4 Replies
TimP
Black Belt
1,336 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.
Vladimir_P_Intel2
1,336 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
TimP
Black Belt
1,337 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

jerryleo
Beginner
1,336 Views
Thanks for all kindly help

Jerry
Reply