简体   繁体   English

不需要的sal.h警告

[英]Unwanted sal.h warnings

I'm trying to use VS 2008 for compiling some C code. 我正在尝试使用VS 2008来编译一些C代码。 I configured the project to use ANSI C standard without any language extensions. 我将项目配置为使用ANSI C标准,没有任何语言扩展。 I also upped the warning level from 3 to 4. 我还将警告级别从3提高到4。

Upon building the project I always get this warning: 在构建项目时,我总是收到此警告:

c:\program files\microsoft visual studio 9.0\vc\include\sal.h(108) : warning C4001: nonstandard extension 'single line comment' was used

I understand the warning, but how do I get rid of it? 我理解这个警告,但我怎么摆脱它呢? I did not include sal.h anywhere. 没有在任何地方包含sal.h。 Also, when creating the solution I chose Win32 Console Application and checked the "Empty Project" checkbox. 此外,在创建解决方案时,我选择了Win32 Console Application并选中了“Empty Project”复选框。

EDIT: I enabled the /showIncludes switch as suggested, but it doesn't really help since it does not show what includes what. 编辑:我按照建议启用了/ showIncludes开关,但它并没有真正帮助,因为它没有显示包含什么的内容。 It seems that VS includes a bunch of stuff on its own: VS似乎包含了很多东西:

Compiling...
go.c
Note: including file: c:\projects\c\kr\kr\e.01.01.h
Note: including file:  c:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h
Note: including file:   c:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
Note: including file:    c:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h
c:\program files\microsoft visual studio 9.0\vc\include\sal.h(108) : warning C4001: nonstandard extension 'single line comment' was used
Note: including file:    c:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtassem.h
Note: including file:    c:\Program Files\Microsoft Visual Studio 9.0\VC\include\vadefs.h
Note: including file:   c:\Program Files\Microsoft Visual Studio 9.0\VC\include\swprintf.inl
Linking...

Am I missing some compiler switch? 我错过了一些编译器开关吗?

#pragma warning( disable:4001)

Put this somewhere to be compiled before the lines with problems. 把这个放在有问题的行之前编译的地方。

For more details, see #pragma warning documentation in MSDN. 有关更多详细信息,请参阅MSDN中的#pragma warning documentation。

Later edit 稍后编辑

Use the option from Visual C++ to display the include files when compiling (it should be somewhere in the advanced options in C++ section). 使用Visual C ++中的选项在编译时显示包含文件(它应该在C ++部分的高级选项中的某个位置)。 It can provide an idea where sal.h is included. 它可以提供包含sal.h的想法。 Probably some of the VC libraries include this header indirectly. 可能一些VC库间接包含此标头。 If it is a C header, I wonder why they used C++ style comments... 如果它是一个C头,我想知道为什么他们使用C ++风格的评论...

Unfortunately you're kind of stuck - Microsoft's runtime headers seem to use single line comments in more than just sal.h (for example, stdlib.h uses them, too), so you can either: 不幸的是你有点卡住了 - 微软的运行时头文件似乎不仅仅使用单行注释sal.h (例如, stdlib.h使用它们),所以你可以:

  • wrap the #include directives with pragmas to disable the warning while they're being included and reenable them afterward 使用pragma包装#include指令以在包含它们时禁用警告并在之后重新启用它们
  • submit a bug report to MS at the Visual Studio connect site Visual Studio连接站点向MS提交错误报告
  • use some other runtime library (maybe Dinkumware will let you compile ANSI clean?) 使用其他一些运行时库(也许Dinkumware会让你编译ANSI干净?)
  • give up on disabling extensions (I'd like to know if anyone successfully uses that option for more than small demonstrations or experiments) 放弃禁用扩展(我想知道是否有人成功地使用该选项而不是小型演示或实验)

or some combination of the above. 或上述的某种组合。

Option #1 is likely to get you going pretty easily: 选项#1很可能让你很容易走:

#pragma warning( push)
#pragma warning( disable : 4001)

#include <stdlib.h>

/* other runtime includes */
#pragma warning( pop)

But I wouldn't be at all surprised if there are other non-ANSI things in the runtime headers. 但是如果运行时头文件中还有其他非ANSI内容,我也不会感到惊讶。 It looks like they've made some attempt to be ANSI clean for when the option was given, but I suspect it's not heavily tested (particularly at non-default warning levels). 在给出选项时,看起来他们已经尝试将ANSI清理干净,但我怀疑它没有经过严格测试(特别是在非默认警告级别)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM