6

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.

MRebai
  • 5,344
  • 3
  • 33
  • 52
  • Don't include both files, or #undef it before including the second one. The problem you'll have is if they don't define it the same way. – Retired Ninja Aug 08 '14 at 10:53
  • Here is the definition in both files: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdint.h(76):#define INT8_MAX 0x7f C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\intsafe.h(167):#define INT8_MAX 127i8 – MRebai Aug 08 '14 at 10:56
  • I was getting a similar warning while building C++ ATL COM dll, I am not getting any such warning after the removing the `#include #include ` include statement from the `stdafx.h` file – Atul N May 10 '19 at 06:32

2 Answers2

11

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.

Chris Warkentin
  • 131
  • 1
  • 7
  • The duplicate definitions are equivilent but not identical which cause the warnings. It is safe to ignore the warnings. I put this in the stdafx.h file for the project with the problem to surpress the warnings. – ChetS Nov 30 '16 at 19:31
2

In order simply to make the message go away, you can add the line

#pragma warning (disable : 4005)

before your first #include statement

But that doesn't mean you shouldn't heed the warning. See if you can do without one of the two header files, and if not, be very certain of which definition your program is using.

Logicrat
  • 4,438
  • 16
  • 22
  • And where to put that #pragma is that in stdint.h or inthe main header – MRebai Aug 08 '14 at 10:59
  • Put it in your program, before you have either `#include "stdint.h"` or '#include "instate.h"` The pragma should precede the first of those #includes. – Logicrat Aug 08 '14 at 11:08
  • Also, do not forget to use the push/pop pragmas so you treat your warning exceptions exactly as you want (See: http://cpphints.com/hints/22) – Dani bISHOP Dec 18 '15 at 09:20