use*_*463 6 c++ language-lawyer
标准说:
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 ]
显然,标准不能涵盖所有可能的行为方面.因此,如果标准不涵盖某些内容,它似乎"可能"是未定义的行为.这到底是什么意思呢?
这意味着,如果标准没有涵盖某些内容,则不能对其施加要求.但是,如果没有明确说明标准,标准怎么说是未定义的行为呢?从字面上看,任何事情都可以在程序中发生,并且假定它不是未定义的行为,除非按照标准这样说.这是否意味着默认情况下非标准程序是未定义的行为?
一位回答说,笔记是非规范性的.在C++标准的非核规范的核心语言规范中的注释和示例中对此进行了解答.其中说:
集成在文档文本中的注释和示例仅用于提供有助于理解或使用文档的其他信息.它们不应包含要求("应";见3.3.1和表H.1)或任何被认为对文件使用必不可少的信息,例如说明(必要;见表H.1),建议("应";见3.3.2和表H.2)或许可("可";见表H.3).注释可以写成事实陈述.
在我看来,省略的东西不是严格的未定义行为.例如,如果在注释中提到它,是严格未定义的行为吗?
但是,如果没有明确说明标准,标准怎么说是未定义的行为呢?
因为那是undefined的意思.发生的事情尚未确定.该标准定义了什么是预期的有效方案,它并不试图列出所有可能的无效程序,并说"这是不确定的,也没有定义,也没有定义".
该标准未指定在程序运行时触发计算机时会发生什么.这并不意味着它定义明确.这显然是未定义的.
从字面上看,任何事情都可以在程序中发生,并且假定它不是未定义的行为,除非按照标准这样说.
我不确定你在这里想说什么,但它听起来是向后倾斜180°.
这是否意味着默认情况下非标准程序是未定义的行为?
什么是"非标准程序"?