调用NULL指针上的删除 – C 03对C 11

在C 03标准中,我看到:

5.3.5 Delete

2 If the operand has a class type,the operand is converted to a pointer type by calling the above-mentioned conversion function,and the converted operand is used in place of the original operand for the remainder of this section. In either alternative,if the value of the operand of delete is the null pointer the operation has no effect. In the first alternative (delete object),the value of the operand of delete shall be a pointer to a non-array object or a pointer to a sub-object (1.8) representing a base class of such an object (clause 10). If not,the behavior is undefined. In the second alternative (delete array),the value of the operand of delete shall be the pointer value which resulted from a prevIoUs array new-expression.72) If not,the behavior is undefined.

在C11标准草案(N3337)中,我看到:

5.3.5 Delete

2 If the operand has a class type,and the converted operand is used in place of the original operand for the remainder of this section. In the first alternative (delete object),the value of the operand of delete may be a null pointer value, a pointer to a non-array object created by a prevIoUs new-expression,or a pointer to a subobject (1.8) representing a base class of such an object (Clause 10). If not,the value of the operand of delete may be a null pointer value or a pointer value that resulted from a prevIoUs array new-expression. If not,the behavior is undefined.

我强调了两个标准中的规格之间的差异.我觉得奇怪的是,2003年的标准更重要的是如何处理NULL指针,而2011年的标准没有说明实现必须做什么.

>标准草案和实际标准之间的C11标准是否有变动?如果是这样,怎么样?
>如果标准草案的标准在实际标准中保持不变,那么在2003年至2011年间几乎没有任何变化的理由是什么呢?

解决方法

看来我们可以在 defect report 348这个变化中找到一个理由,它说:

Specifically,standard says in 5.3.5 [expr.delete] paragraph 2:

…if the value of the operand of delete is the null pointer the operation has no effect.


标准没有指定术语“没有效果”.不清楚
这个上下文,是否需要所谓的解除分配功能
没有效果,或者delete-expression不能调用解除分配
功能.

此外,在第4段标准中说明了认的解除分配功能

If the delete-expression calls the implementation deallocation
function (3.7.4.2 [basic.stc.dynamic.deallocation]),if the operand of
the delete expression is not the null pointer constant,…


为什么认解除分配函数和delete-expr的交互是如此具体?

如果“没有效果”是解除分配功能的要求,那么
应该在3.7.4.2 [basic.stc.dynamic.deallocation]或者
18.6.1.1 [new.delete.single]和18.6.1.2 [new.delete.array],应该明确说明.

解决方案的一部分是您注意到的措辞的变化,虽然该短语的语言已经发生了很大的变化,但是驾驶的逻辑没有效果语言仍然存在,但这不是一个明确的术语,因此应该是用指定的语言替代.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...