2
#ifdef ???
    // code for VC++ 2010 compiler
#else
    // code for later compiler versions
#endif

What macro can I use instead of ???? I don't care about older compiler versions.

Alex F
  • 42,307
  • 41
  • 144
  • 212
  • 2
    To be honest, I didn't get the question – billz Jan 09 '14 at 11:09
  • 3
    [google is your friend](http://msdn.microsoft.com/en-us/library/b0084kay.aspx). Specifically, look at the `_MSC_VER`-type macros. Note that they use _compiler_ version, not the IDE version. – icabod Jan 09 '14 at 11:11
  • 1
    @billz: For example, code line `TestClass(const TestClass&) = delete;` is not compiled in VC++ 2010, but I want to have it here for VC++ 2012 and VC++ 2013 compilers. So, I need some precompiler macro to exclude this line, when VC++ 2010 is used. – Alex F Jan 09 '14 at 11:14
  • I use http://sourceforge.net/p/predef/wiki/Home/ for the list of predefined macros. – Jarod42 Jan 09 '14 at 11:41

2 Answers2

3

For VS2010 or later:

#if _MSC_VER >= 1600

Since the C/C++ compiler included with VS2010 is version 16.00.x (as displayed at the command line by cl.exe).

See http://msdn.microsoft.com/en-us/library/b0084kay%28v=vs.100%29.aspx

For some measure of completeness:

Visual Studio   _MSC_VER
   version        value
=============  ===========
      6             1200

   2002             1300
   2003             1310
   2005             1400

   2008             1500
   2010             1600
   2012             1700

   2013             1800
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • I would probably have a nested check also, so that you cover the three options from the "question"... earlier than v16 (display a warning), v16, and later than v16. – icabod Jan 09 '14 at 11:17
2
#if (_MSC_VER == 1600)
   //Visual C++ 2010 compiler code here...

Should do what you want. From here: How to Detect if I'm Compiling Code With Visual Studio 2008?

Community
  • 1
  • 1
Andrea
  • 6,032
  • 2
  • 28
  • 55