gpt4 book ai didi

c++ - 未定义的行为可以删除硬盘驱动器吗?

转载 作者:IT老高 更新时间:2023-10-28 21:44:25 25 4
gpt4 key购买 nike

来自“Effective C++ 3rd edition by Scott Meyers”:

To emphasize that the results of undefined behavior are not predictable and may be very unpleasant, experienced C++ programmers often say that programs with undefined behavior can erase your hard drive.

在什么情况下会发生这种情况?

例如,访问和写入超出数组范围的位置是否会损坏不属于此 C++ 程序或线程的内存?

最佳答案

可以吗?当然。事实上,发生在我身上。

我编写了删除临时目录的代码。这涉及创建 recursive delete <temp directory>\*.*命令。由于一个错误,<temp directory>字段并不总是填写。我们的文件系统代码愉快地执行了 recursive delete \*.*命令。

我的同事注意到他们桌面上的图标突然消失了。拿出两台机器。

关于c++ - 未定义的行为可以删除硬盘驱动器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18506029/

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