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

问题描述

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

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

解决方案

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

这不允许在编译器的单次运行中更改行为。但是在编译器的不同运行之间,根据定义的实现,编译器可以使用根据不同的实现定义的值而不同的不同的对应抽象机。像 -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:

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:

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

10-29 20:59