gpt4 book ai didi

c++ - Visual Studio 调试迭代器

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:22:02 24 4
gpt4 key购买 nike

_SECURE_SCL之间有什么关系?和 _HAS_ITERATOR_DEBUGGING .是否可以打开/关闭范围检查并保持二进制兼容性?

2008 和 2010 版本之间有什么区别吗?

最佳答案

Stephan Lavavej 提供了有关此 _SECURE_SCL_HAS_ITERATOR_DEBUGGING 的一些详细信息:

来自 http://blogs.msdn.com/b/vcblog/archive/2007/08/10/the-future-of-the-c-language.aspx

Iterator debugging, enabled by _HAS_ITERATOR_DEBUGGING, performs powerful correctness verification. Iterator checking, enabled by _SECURE_SCL, performs minimal checks that serve as a last line of security defense. For example, _SECURE_SCL will terminate a program that triggers a heap overrun with a vector iterator.

All that is explained by MSDN documentation. The story behind this is interesting. The _HAS_ITERATOR_DEBUGGING functionality was provided by Dinkumware, the company that licenses their most triumphant implementation of the Standard Library for inclusion in Visual Studio. The _SECURE_SCL functionality was added by Microsoft, in order to improve the security of programs running on Windows. In order to perform their checks, both _HAS_ITERATOR_DEBUGGING and _SECURE_SCL make iterators contain additional data members, such as pointers to their parent containers. _HAS_ITERATOR_DEBUGGING, because it is enabled by default in debug mode (and not obtainable in release mode), also builds singly linked lists that allow containers to refer to all of their iterators. This is expensive performance-wise, but performance is not critical in debug mode, and this enables excellent checks.

_SECURE_SCL, because it is enabled by default in release mode, strives to impose minimal performance penalties. Therefore, when it is enabled, although iterators have pointers back to their containers, containers don't have pointers to their iterators. (Updating "iterator lists" is too time-consuming for release mode.)

请注意,从 VS 2010 开始,_SECURE_SCL 在 Release模式下不再默认启用(以上摘录自 2007 年)。

如错误报告 (http://connect.microsoft.com/VisualStudio/feedback/details/334315/has-iterator-debugging-0-causes-crash) 中所述,_SECURE_SCL_HAS_ITERATOR_DEBUGGING 都会影响 ABI:

_SECURE_SCL and _HAS_ITERATOR_DEBUGGING significantly change the behavior and representations of STL containers and iterators. VC9 (Visual Studio 2008) made the representations of STL containers and iterators even more strongly dependent on _SECURE_SCL and _HAS_ITERATOR_DEBUGGING (this was done to fix a conformance bug).

Because these macros change the representations of STL objects, you must observe certain rules when changing these macros from their defaults. I described the rules here: http://blogs.msdn.com/vcblog/archive/2007/08/10/the-future-of-the-c-language.aspx#4617984 To summarize, the macros must be consistent within each binary (EXE or DLL), and furthermore, binaries that pass STL objects to each other must have consistent macro settings. Your example involves an EXE and DLL passing a vector between themselves, so the EXE and DLL need to have the same _SECURE_SCL and _HAS_ITERATOR_DEBUGGING settings.

These rules apply to VC8, VC9, and all future versions. Your code happened to work with VC8 (Visual Studio 2005), but would fail if it did more complicated things.

关于c++ - Visual Studio 调试迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6103314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com