4

Possible Duplicate:
Detect compiler with #ifdef

Greetings all,

I've been working on a C++ project using gcc on linux and mingw on windows.Now I want to use VC++ cl compiler on Windows. I was to keep the same source code tree only change the compiler specific logic like:

#ifdef VC_CL_COMPILER
 //do vc++ related
#elif MINGW_FLAG
 //do mingw related
#elseif GCC_FLAG
  //do gc related    
#endif

Anyway tips on doing this?

Community
  • 1
  • 1
Ashika Umanga Umagiliya
  • 8,988
  • 28
  • 102
  • 185
  • Reason for reopening: I think gcc deserves a special case, as the `__GNUC__` flag is defined also by other compilers. See [here](http://sourceforge.net/p/predef/wiki/Compilers/#gcc-cc). – Antonio Jan 27 '16 at 10:47

1 Answers1

12

Compilers usually have a predefined macro for this.

#if defined(__GCC__)
  //do gcc related
#elif defined(_MSC_VER)
  //do msvc related
#else

#endif
Marlon
  • 19,924
  • 12
  • 70
  • 101
  • 7
    Gcc v4.1 ( and probably others) doesn't define `__GCC__` . It is `__GNUC__` that should be tested. – iksess Sep 10 '14 at 15:14