可以未定义的行为删除硬盘驱动器? [英] Can undefined behavior erase the hard drive?
问题描述
FromEffective C ++ 3rd edition by Scott Meyers:
From "Effective C++ 3rd edition by Scott Meyers":
要强调未定义行为的结果是不可预测的,非常不愉快,经验丰富的C ++程序员经常说,具有未定义行为的程序可以擦除您的硬盘驱动器。
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 ++程序或线程的数组范围损坏的内存中的位置?
For example, can accessing and writing to locations out of array range corrupt memory that doesn't belong to this C++ program or thread?
推荐答案
可以吗?当然。对我来说,事实上。
Can it? Sure. Happened to me, in fact.
我写了代码来删除临时目录。这涉及创建递归删除< temp directory> \ *。*
命令。由于一个错误,< temp directory>
字段并不总是填充。我们的文件系统代码很高兴执行递归删除\ * 。*
命令。
I wrote code to delete a temporary directory. That involved creating a recursive delete <temp directory>\*.*
command. Due to a bug, the <temp directory>
field wasn't always filled in. Our file system code happily executed the recursive delete \*.*
command.
我的同事注意到桌面上的图标突然消失。出去两台机器。
My colleagues noticed when the icons on their desktop suddenly disappeared. Took out two machines.
这篇关于可以未定义的行为删除硬盘驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!