Macro redefinition warnings

随声附和 提交于 2019-12-23 04:42:40

问题


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.


回答1:


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:


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



来源:https://stackoverflow.com/questions/12516584/macro-redefinition-warnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!