Fix macro redefinition in C++

Moez Rebai picture Moez Rebai · Aug 8, 2014 · Viewed 10.3k times · Source

Since intsafe.h and stdint.h both define INT8_MIN. Thus VS2010 generate a warning that says :

    1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdint.h(72): warning C4005: 'INT8_MIN' : macro redefinition
1>          C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\intsafe.h(144) : see previous definition of 'INT8_MIN'

Is there a way to fix that warning in VS2010.

Answer

Chris Warkentin picture Chris Warkentin · Mar 18, 2016

Apparently it's a bug in VS2010. You can avoid it in general but in MFC applications it's basically impossible to ever include stdint.h in any of your other code without hitting it.

I just did this at the top of the file that was complaining:

#pragma warning (push)
#pragma warning (disable : 4005)
#include <intsafe.h>
#include <stdint.h>
#pragma warning (pop)

It gets those headers 'out of the way' so to speak and lets you get on with your day.