Fix for error C2373 after upgrading to VS2008 SP1

After upgrading to Visual Studio 2008 Service Pack 1, you may receive the following error when compiling C++ code:

C:\Program Files\VStudio9\VC\include\intrin.h(204) : error C2373: '_InterlockedCompareExchange' : redefinition; different type modifiers
C:\Program Files\VStudio9\VC\include\memory(995) : see declaration of '_InterlockedCompareExchange'

This bug was first noted in the comments to the release notes for the Visual C++ 2008 Feature Pack. The Visual C++ team added a workaround in the final release of VC9 SP1; this workaround is buried (as point #13) in the TR1 fixes post.

To fix the problem, define the symbol _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY for the affected project. I found that it was easiest to do this by adding these two lines to StdAfx.h:

#include <intrin.h>

Posted by Bradley Grainger on August 15, 2008