Fix macro redefinition in C++

11,411

Solution 1

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.

Solution 2

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.

Share:
11,411
Moez Rebai
Author by

Moez Rebai

Updated on June 26, 2022

Comments

  • Moez Rebai
    Moez Rebai almost 2 years

    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.

  • Moez Rebai
    Moez Rebai over 9 years
    And where to put that #pragma is that in stdint.h or inthe main header
  • Logicrat
    Logicrat over 9 years
    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.
  • Dani bISHOP
    Dani bISHOP over 8 years
    Also, do not forget to use the push/pop pragmas so you treat your warning exceptions exactly as you want (See: cpphints.com/hints/22)
  • ChetS
    ChetS over 7 years
    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.