Mahesh
Mahesh

Reputation: 34625

Macro redefinition warnings

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.

Upvotes: 0

Views: 10159

Answers (2)

SomeWittyUsername
SomeWittyUsername

Reputation: 18368

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

Upvotes: 2

SingerOfTheFall
SingerOfTheFall

Reputation: 29976

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.

Upvotes: 2

Related Questions