The C specification defines various types of program behavior, including undefined, unspecified, implementation-defined, erroneous, and ill-formed. While some distinctions are relatively clear, the term "ill-formed; no diagnostic required" has raised questions about its precise meaning.
Ill-formed: A program that violates either the syntax or diagnosable semantic rules.
Undefined behavior: Program behavior for which the standard makes no assumptions or requirements about the implementation's actions.
Erroneous: A term used by the standard to indicate that a program is ill-formed or engages in undefined behavior.
Well-formed: A program that adheres to the syntax and diagnosable semantic rules.
This specific wording appears when an implementation extends the language in a way that introduces new syntax or behavior. According to the standard, such extensions are considered ill-formed, but the implementation is permitted not to issue a diagnostic message.
The crucial distinction here is that undefined behavior explicitly acknowledges the erroneous nature of the program, while "ill-formed; no diagnostic required" refers to a specific case where the implementation allows a violation without providing a clear error message.
An ill-formed program should technically not compile. However, in the case of "ill-formed; no diagnostic required," the implementation is technically allowed to silently compile and even execute the program without warning.
The standard's inconsistent use of terminology surrounding errors has led to confusion. The term "erroneous" implies an error requiring a diagnostic, but the "Note" section in 1.3.13 permits implementations to silently ignore such problems.
While there may be a subtle difference between "ill-formed; no diagnostic required" and "undefined behavior," the standard's inconsistency makes it challenging to draw clear distinctions. Ultimately, both terms refer to situations where the program's behavior is unpredictable and may result in unexpected outcomes.
The above is the detailed content of What\'s the Difference Between C \'s \'Undefined Behavior\' and \'Ill-Formed; No Diagnostic Required\'?. For more information, please follow other related articles on the PHP Chinese website!