是否需要实现定义的行为在C ++中的运行之间是一致的? [英] Is implementation-defined behavior required to be consistent between runs in C++?

查看:150
本文介绍了是否需要实现定义的行为在C ++中的运行之间是一致的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个符合标准的C ++实现允许实现一些被称为在标准中实现定义的行为,使得它在具有相同输入数据的相同编译一次程序的不同运行之间是不同的。 p>

例如,是一个实现允许说周末的行为是这样的,否则,并根据这样的语句实现行为?

解决方案

当然,如果实现文档中的行为更改与不同的运行,这很好。注意,实现定义的行为是抽象机参数的一部分:


本国际标准中的语义描述定义了参数化非确定性抽象
机器。



抽象机的某些方面和操作在本国际标准中被描述为实现定义的(例如sizeof(int))。这些构成了抽象机的参数。每个实施应包括描述其在这些方面的特性和行为的文档。这样的文档应该定义对应于该实现的抽象机的实例(以下称为对应实例)。


这不允许在编译器的单次运行中更改行为。但是在编译器的不同运行之间,根据定义的实现,编译器可以使用根据不同的实现定义的值而不同的不同的对应抽象机。像 -Wall (更改实现定义的诊断消息集)的命令行参数是最常见的示例。除了文档要求之外,这是对未指定行为的区别。未指定的行为限制较少:


抽象机器的某些其他方面和操作在本国际标准中被描述为未指定(例如,函数参数的求值顺序)。在可能的情况下,本国际标准定义了一组允许的行为。这些定义了抽象机的非确定性方面。抽象机的实例因此可以具有用于给定程序和给定输入的多于一个可能的执行序列。



Is a standard-conforming C++ implementation allowed to implement some behavior that is said to be implementation-defined in the standard in such way that it is different between different runs of the same compiled once program with the same input data?

For example, is an implementation allowed to say "the behavior is this on weekends and that otherwise" and implement behavior according to such statement?

解决方案

Of course, if the implementation documents when exactly the behavior changes with different runs, that's fine. Notice that the implementation-defined behavior is part of the parameters of the abstract machine:

The semantic descriptions in this International Standard define a parameterized nondeterministic abstract machine.

Certain aspects and operations of the abstract machine are described in this International Standard as implementation-defined (for example, sizeof(int)). These constitute the parameters of the abstract machine. Each implementation shall include documentation describing its characteristics and behavior in these respects. Such documentation shall define the instance of the abstract machine that corresponds to that implementation (referred to as the ‘‘corresponding instance’’ below).

This does not allow changing the behavior in a single run of the compiler. But between different runs of the compiler, the compiler may use a different corresponding abstract machine which differs by different implementation defined values, according to what the implementation defined. Command line parameters like -Wall (which changes the implementation-defined set of diagnostic messages) are the most common example of this. This is a difference to unspecified behavior in addition to the documentation requirements. Unspecified behavior is much less restrictive:

Certain other aspects and operations of the abstract machine are described in this International Standard as unspecified (for example, order of evaluation of arguments to a function). Where possible, this International Standard defines a set of allowable behaviors. These define the nondeterministic aspects of the abstract machine. An instance of the abstract machine can thus have more than one possible execution sequence for a given program and a given input.

这篇关于是否需要实现定义的行为在C ++中的运行之间是一致的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆