遗漏是某种不确定的行为吗? [英] Is something undefined behavior by omission?

查看:69
本文介绍了遗漏是某种不确定的行为吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准说:

1.3.24                                                          [defns.undefined]
undefined behavior
behavior for which this International Standard imposes no requirements
[ Note: Undefined behavior may be expected when this International Standard 
omits any explicit definition of behavior or when a program uses an erroneous 
construct or erroneous data. Permissible undefined behavior ranges from ignoring 
the situation completely with unpredictable results, to behaving during 
translation or program execution in a documented manner characteristic of the 
environment (with or without the issuance of a diagnostic message), to 
terminating a translation or execution (with the issuance of a diagnostic 
message). Many erroneous program constructs do not engender undefined behavior; 
they are required to be diagnosed.
— end note ]

很显然,该标准不能涵盖行为的所有可能方面.因此,似乎如果该标准未涵盖某些内容,则它可能"是未定义的行为.到底是什么意思?

Clearly the standard can not cover every possible facet of behavior. So it seems that if something is not covered by the standard, it "may" be undefined behavior. What exactly does that mean?

这意味着如果该标准未涵盖某些内容,则不会对其施加任何要求.但是,标准如何在没有明确说明的情况下说出某些事情是未定义的行为?从字面上看,任何事情都可能在程序中发生,除非标准另有规定,否则它不是未定义的行为.这是否意味着非标准程序默认情况下是未定义的行为?

It's implied that if the standard does not cover something, it can't impose requirements on it. However, how can the standard say something is undefined behavior without explicitly saying so? Literally anything can happen in a program and it is assumed that it is not undefined behavior unless said so by the standard. Does this mean a non-standard program is undefined behavior by default?

回答者说注释不是规范性的.在中得到了回答C ++标准的核心语言规范中的注释和示例是否是非规范性的?其中说:

An answerer says notes are non-normative. This is answered in Are notes and examples in the core language specification of the C++ Standard non-normative? which says:

文档正文中的注释和示例仅应为 用于提供其他信息以帮助 对文档的理解或使用.它们不得包含 要求(应";请参见3.3.1和表H.1)或任何信息 被认为对于使用文件必不可少的 说明(必须;请参见表H.1),建议(应"; 请参阅3.3.2和表H.2)或许可(可能";请参见表H.3).笔记 可以写成事实陈述.

Notes and examples integrated in the text of a document shall only be used for giving additional information intended to assist the understanding or use of the document. They shall not contain requirements ("shall"; see 3.3.1 and Table H.1) or any information considered indispensable for the use of the document, e.g. instructions (imperative; see Table H.1), recommendations ("should"; see 3.3.2 and Table H.2) or permission ("may"; see Table H.3). Notes may be written as a statement of fact.

那么在我看来,被忽略的东西并不是严格未定义的行为.例如,如果在注释中提到了某些行为,则该行为是完全未定义的行为吗?

It seems to me then that something that is omitted is not strictly undefined behavior. For example, is something strictly undefined behavior if it's mentioned in a note?

推荐答案

但是,标准如何在没有明确说明的情况下说出某种未定义的行为?

However, how can the standard say something is undefined behavior without explicitly saying so?

因为这就是未定义的意思.发生的情况尚未确定.该标准定义了对有效程序的期望 ,它不会尝试列出所有可能的无效程序,并说这是未定义的,这也是未定义的,这也是未定义的".

Because that's what undefined means. What happens has not been defined. The standard defines what is expected of a valid program, it doesn't attempt to list every conceivable invalid program and say "this is undefined, also this is undefined, also this is undefined".

如果程序运行时对计算机起火,该标准未指定会发生什么.这并不意味着它定义明确.显然是不确定的.

The standard doesn't specify what happens if you set fire to your computer while the program is running. That doesn't mean it's well-defined. It's clearly undefined.

从字面上看,程序中可能发生任何事情,并且除非标准中没有规定,否则它不是未定义的行为.

Literally anything can happen in a program and it is assumed that it is not undefined behavior unless said so by the standard.

我不确定您要在这里说些什么,但听起来向后倾斜180°.

I'm not sure what you're trying to say here, but it sounds 180° backwards.

这是否意味着默认情况下非标准程序是未定义的行为?

Does this mean a non-standard program is undefined behavior by default?

什么是非标准程序"?

这篇关于遗漏是某种不确定的行为吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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