views:

283

answers:

2

Is there a (Microsoft-specific) CPP macro to determine when I'm using the VC9 compiler in Visual Studio 2010 as opposed to Visual Studio 2008? _MSC_VER returns the compiler version, so with VS2010 multi-targeting feature, I'll get the same result as with VS2008.

The reason for wanting to know the difference is that I created a new VS2010 project which contains code removed from a larger project. I just left the VS2008 stuff "as is" since we're moving away from VS2008 "soon" anyway and I didn't want to go through the hassle of creating a vcproj file along with the new vcxproj.

For now, I've just defined my own macro to indicate whether the code is compiled into its own DLL or not; it works just fine, but it would be nice if there were something slightly more elegant.

A: 

_MSC_VER returns the compiler version

It sounds like that's what you really do want (or am I misunderstanding?).

If the compiler from VS2008 (which confusingly is also known as VC9 or cl.exe 15.0) is being used, then _MSC_VER will return a value that's greater than or equal to 1500. If the compiler from VS2010 is used (also known as VC10 or cl.exe 16.0), then _MSV_VER will evaluate to 1600.

Michael Burr
@James - I see. I'll have to check that out; if that's the case, that sure sounds to me like a bug that should be filed with MS.
Michael Burr
I want to know with which IDE (VS2008 or VS2010 w/multi-targeting) I'm using the VC9 compiler; and w/o having to define my own macro.
Dan
@Dan - I see. Can you give an bit more detail on why you want to know which IDE is kicking off the build? I'm curious about understanding the motivation.
Michael Burr
I need to setup the __declspec(...) correctly: in VS2008, all the code is in a single project; in VS2010 I've split off some code into a new DLL. I'm just trying to avoid the hassle of creating a corresponding VCPROJ file that likely won't be around long anyway.
Dan
A: 

[ trying to keep my 100% accept rate ]

It seems there is no solution, a custom macro works even if it isn't quite as elegant as I would like.

Dan