0
votes

I am migrating a windows driver project from VS 2005 to VS 2012. Many macro redefinition warnings are generated on VS 2012 like -

....

1>C:\WINDDK\7600.16385.1\inc\api\sal.h(707): warning C4005: '__format_string' : 
                                                                macro redefinition
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2860) : 
                                       see previous definition of '__format_string'

.....

It was compiling fine with sal.h shipped with VS 2005 because it doesn't have the macro __format_string and others. However, the sal.h shipped with VS 2012 has these macros. Thus having conflicts between the driver's sal.h and the standard sal.h with VS 2012.

#define __format_string                            // With DDK
#define __format_string    _Printf_format_string_  // On VS 2012

I cannot ignore the standard headers because they are used in the build process.

....
1> Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\string.h
1> Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h
....

There is no #if directive around these macros in sal.h so that I can #undef it in VS 2012. Is there any work around for this issue ?

Thanks.

2
Do you need to use both the VS' macros and your own macros in the same project, or do you just want to get rid of the warnings? - SingerOfTheFall
In neither case, they are my own macros. Both are coming from standard header sal.h but from different include paths( WinDDK, VS 2012 Standard Include Path ) . And yes, I want to get rid of warnings not by saying to ignore this warning. But with a more formal way, if exists. - Mahesh
The more formal way to get rid of the warnings is to add a #undef before each macro definition. But that will end up producing its own warnings if the macro being undef'd hasn't been defined. It's perfectly legal to do that, but compiler writers apparently figure that you're not smart enough to have meant to do it. Unfortunately, doing that means editing system headers, which some people frown on. - Pete Becker
@PeteBecker I don't like modifying standard headers and neither of my team members :( - Mahesh
VS2012 doesn't support XP right now. - Hans Passant

2 Answers

2
votes

Well if I understood what you want correctly, all you need to do is add

#ifdef __format_string 
#undef __format_string
#endif

before the redefinitions.

2
votes

You shouldn't include the VS standard headers in driver code, they aren't for kernel usage. Use WDK headers only.