[英]Can an operation defined as implementation-defined behavior have multi possible execution?
[conv.fpint] p2 says [conv.fpint] p2 说
If the value being converted is in the range of values that can be represented but the value cannot be represented exactly, it is an implementation-defined choice of either the next lower or higher representable value.
如果要转换的值在可以表示的值范围内但不能准确表示,则它是下一个较低或较高可表示值的实现定义选择。
[intro.abstract] p2 says [intro.abstract] p2 说
Certain aspects and operations of the abstract machine are described in this document as implementation-defined (for example,
sizeof(int)
).抽象机的某些方面和操作在本文档中描述为实现定义(例如
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).
此类文档应定义与该实现相对应的抽象机器的实例(以下称为“对应实例”)。
[intro.abstract] p5 says [intro.abstract] p5 说
A conforming implementation executing a well-formed program shall produce the same observable behavior as one of the possible executions of the corresponding instance of the abstract machine with the same program and the same input.
执行格式良好的程序的一致实现应产生与具有相同程序和相同输入的抽象机的相应实例的可能执行之一相同的可观察行为。 However, if any such execution contains an undefined operation, this document places no requirement on the implementation executing that program with that input (not even with regard to operations preceding the first undefined operation).
但是,如果任何此类执行包含未定义的操作,则本文档对使用该输入执行该程序的实现没有任何要求(甚至不考虑第一个未定义操作之前的操作)。
Consider that there is an implementation, which cannot represent the value 16777217
exactly in an object of float type, and the choice for such a value can be either 16777216
or 16777218
.考虑有一个实现,它不能在浮点类型的对象中精确地表示值
16777217
,并且这种值的选择可以是16777216
或16777218
。 For all odd times of the evaluation of the conversion, it chooses the lower representable value, and for all even times of evaluation of the conversion, it chooses the higher representable value.对于转换评估的所有奇数次,它选择较低的可表示值,并且对于转换评估的所有偶数次,它选择较高的可表示值。 Is this a conforming implementation?
这是一个符合要求的实现吗?
float a1 = 16777217; // 16777216
float a2 = 16777217; // 16777218
.
.
.
float a<2n-1> = 16777217; // 16777216
float a<2n> = 16777217; // 16777218
A resemble case:一个类似的案例:
sizeof(int); // 4
sizeof(int); // 8
.
.
.
sizeof(int); // 4
sizeof(int); // 8
For all odd times of the evaluation of sizeof(int)
, the results are all 4
, and for all even times of evaluation of sizeof(int)
, the results are all 8
.对于
sizeof(int)
的所有奇数次求值,结果都是4
,而对于sizeof(int)
的所有偶数次求值,结果都是8
。
Technically, yes.从技术上讲,是的。 You already quoted the relevant text so my answer will not include any further quotes.
您已经引用了相关文本,因此我的回答将不包含任何进一步的引用。 implementation-defined means that the implementation must document the behaviour that it implements.
实现定义意味着实现必须记录它实现的行为。
There is no further constraint on the behaviour than specified in the text you quoted.除了您引用的文本中指定的行为之外,没有进一步的限制。 It would be a quality-of-implementation issue whether the implementation documents a single outcome or a range of outcomes and under what circumstances, etc.
实施是否记录了单个结果或一系列结果以及在什么情况下等,这将是一个实施质量问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.