未定义的行为可以擦除硬盘驱动器吗?

Can undefined behavior erase the hard drive?(未定义的行为可以擦除硬盘驱动器吗?)
本文介绍了未定义的行为可以擦除硬盘驱动器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

来自Scott Meyers 撰写的《Effective C++ 3rd edition》":

<块引用>

为了强调未定义行为的结果是不可预测的,并且可能会非常不愉快,有经验的 C++ 程序员经常说具有未定义行为的程序会擦除您的硬盘驱动器.

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

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

解决方案

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

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

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

From "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.

Under what circumstances can this happen?

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.

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.

这篇关于未定义的行为可以擦除硬盘驱动器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

OpenGL transforming objects with multiple rotations of Different axis(OpenGL 变换不同轴多次旋转的对象)
GLFW first responder error(GLFW 第一响应者错误)
SOIL not linking correctly(SOIL 连接不正确)
Core profile vs version string? Only getting GLSL 1.3/OGL 3.0 in mesa 10.0.1(核心配置文件与版本字符串?在 mesa 10.0.1 中只获得 GLSL 1.3/OGL 3.0)
What is the range of OpenGL texture ID?(OpenGL 纹理 ID 的范围是多少?)
How taxing are OpenGL glDrawElements() calls compared to basic logic code?(与基本逻辑代码相比,OpenGL glDrawElements() 调用的繁重程度如何?)