gpt4 book ai didi

c++ - Linux 上 STL 的安全版本

转载 作者:行者123 更新时间:2023-11-30 00:46:20 25 4
gpt4 key购买 nike

The C++ Standard Library - A Tutorial and Reference, 2nd Edition指的是 STL 的安全版本,它支持各种实用程序,例如 operator [] 和其他运算符的运行时边界检查。例如,在 p247 上:

Thus, it is a good idea to use a "safe" STL, at least during software development. A first version of a safe STL was introduced by Cary Horstmann (see [SafeSTL]). Another example is the "STLport", which is available for free for almost any platform at [STLPort]. In addition, library vendors now provide flags to enable a "safer" mode, which especially should be enabled during development.

这两个建议的包似乎都相对过时(最后开发于 2008 年)并且不包含更新的 C++11/14 功能。 Linux 上的一些主要编译器(gccclang)或作为独立库是否有任何更新的可靠实现可用?

最佳答案

libstdc++ 有一个 debug mode ,可以通过在编译时定义 _GLIBCXX_DEBUG 来启用。

The libstdc++ debug mode performs checking for many areas of the C++ standard, but the focus is on checking interactions among standard iterators, containers, and algorithms, including:

  • Safe iterators: Iterators keep track of the container whose elements they reference, so errors such as incrementing a past-the-end iterator or dereferencing an iterator that points to a container that has been destructed are diagnosed immediately.

  • Algorithm preconditions: Algorithms attempt to validate their input parameters to detect errors as early as possible. For instance, the set_intersection algorithm requires that its iterator parameters first1 and last1 form a valid iterator range, and that the sequence [first1, last1) is sorted according to the same predicate that was passed to set_intersection; the libstdc++ debug mode will detect an error if the sequence is not sorted or was sorted by a different predicate.

operator[] 中的边界检查 is included .

关于c++ - Linux 上 STL 的安全版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38958523/

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