C++ Visual Studio 警告 C4996
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3317536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Warning C4996
提问by Anthony
I'm getting the following warning
我收到以下警告
warning C4996: 'std::_Uninitialized_copy0': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' c:\program files\microsoft visual studio 10.0\vc\include\memory 348
warning C4996: 'std::_Uninitialized_copy0': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' c:\program files\microsoft visual studio 10.0\vc\include\memory 348
I can't seem to find any information that would help to combat this warning. By looking at the output it seems this warning has something to do with Boost.Signals2 and auto_buffer.
我似乎找不到任何有助于消除此警告的信息。通过查看输出,此警告似乎与 Boost.Signals2 和 auto_buffer 有关。
Is this safe to ignore or can I remove it somehow?
忽略它是否安全,或者我可以以某种方式将其删除吗?
回答by ssegvic
First, I would like to say that I am quite fond of compiler warnings. I invoke gcc with -Wall -Wextra.
首先,我想说我非常喜欢编译器警告。我用 -Wall -Wextra 调用 gcc。
However, the MSVC warning C4996 mostly fires on completely valid code. The changes proposed in the warning text often seriously compromise the code portability, while they never substantially improve the code quality. Thus I regularly suppress this warning in my MSVC projects (Project properties->C++->Advanced->Disable specific warnings).
但是,MSVC 警告 C4996 主要针对完全有效的代码触发。警告文本中提出的更改通常会严重损害代码的可移植性,而它们从未显着提高代码质量。因此,我经常在我的 MSVC 项目(项目属性->C++->高级->禁用特定警告)中取消此警告。
回答by DocDJ
This error is generated because the code the compiler produces is not thread-safe. This means that if you are using multi-threaded coding, some of your stream I/O can (and probably will) get lost because the internal I/O buffers are shared. The suggested substitute functions will "eliminate" this problem.
生成此错误是因为编译器生成的代码不是线程安全的。这意味着如果您使用多线程编码,您的一些流 I/O 可能(并且可能会)丢失,因为内部 I/O 缓冲区是共享的。建议的替代功能将“消除”这个问题。