简体   繁体   English

定义为实现定义的行为的操作可以有多种可能的执行吗?

[英]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 ,并且这种值的选择可以是1677721616777218 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

Update:更新:

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.

相关问题 未定义、未指定和实现定义的行为 - Undefined, unspecified and implementation-defined behavior 在哪里查找GCC实现定义行为的实现? - Where to look up GCC's implementation of implementation-defined behavior? 有效的无符号到有符号转换避免实现定义的行为 - Efficient unsigned-to-signed cast avoiding implementation-defined behavior C ++中是否有完整的Implementation-Defined行为列表? - Is there a complete list of Implementation-Defined behavior in C++? 实现定义的行为是否需要在C ++中的运行之间保持一致? - Is implementation-defined behavior required to be consistent between runs in C++? 未定义与未指定与实现定义的行为 - Undefined vs. Unspecified vs. Implementation-defined behavior static 初始化顺序惨败是未定义的还是实现定义的行为? - Is static initialization order fiasco Undefined or Implementation-defined behavior? 实施定义的缩小转换? - Implementation-defined narrowing conversions? 未定义/未指定/实现定义的行为警告? - Undefined/Unspecified/Implementation-defined behaviour warnings? 为什么malloc(0)的返回值是实现定义的? - Why is the return value of malloc(0) implementation-defined?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM