如何在 Visual Studio 2005 中禁止出现警告 4200?
我可以在 C/C++ Advanced 属性页中禁止 Visual Studio 2005 SP1 中的许多警告,这会导致 IDE 在调用编译器的命令行上使用 /wd 开关。 但是,当我尝试禁止警告 4200(使用非标准扩展:结构/联合中的零大小数组)时,它在编译时仍然出现。 (当然这是有道理的;我只是无法修复代码,也不值得打扰,因为它是生成的,并且警告在这种情况下完全是良性的。)碰巧知道这是否是编译器中的错误? 或者我可以做点什么吗?
I can inhibit many warnings in Visual Studio 2005 SP1 in the C/C++ Advanced property page, which causes the IDE to use the /wd switch on the command line which invokes the compiler. However, when I try to inhibit warning 4200 (nonstandard extension used : zero-sized array in struct/union), it still appears when I compile. (Of course it's justified; I'm just not in a position to fix the code, nor would it be worth bothering, because it's generated, and the warning is entirely benign under the circumstances.) Does anybody happen to know if this is a bug in the compiler? Or might there be something I can do about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要完全禁用文件中的警告,您可以将以下内容添加到文件顶部。
如果除了全面禁用文件之外您想要更多的灵活性,下页列出了其他几个更细粒度的选项。
根据您的信息,尚不清楚这是编译器中的错误还是配置问题。 我倾向于配置问题,特别是编译器选项冲突,这使得抑制警告变得困难。
编辑
OP提到他们无法控制生成的代码,因此他们无法直接包含编译指示。 如果是这样的话,请尝试这个技巧。 假设文件名是Generated.cpp。 不再包含 generated.cpp 作为要编译的文件之一。 而是创建一个名为Example.cpp 的新文件,其中包含以下内容。
现在,您只需编译Example.cpp 即可获得带有禁用警告的Generated.cpp 文本。
To completely disable the warning in the file you can add the following to the top of the file
If you want some more flexibility other than a blanket disable for the file, the following page lists several other more fine grained options.
It's unclear based on your information as to whether or not it's a bug in the compiler or a configuration issue. I would lean towards a configuration issue, specifically conflicting compiler options that is making it difficult to suppress the warning.
EDIT
OP mentioned they can't control the generated code so they can't directly include the pragma. If that's the case then try this trick. Say the file name is Generated.cpp. No longer include Generated.cpp as one of the files to compile. Instead create a new file called Example.cpp with the following contents
Now you'll get the text of Generated.cpp with the disabled warning by only compiling Example.cpp.
您的意思是像 pragma 一样?
You mean like with pragma?