Home > Backend Development > C++ > What\'s the Difference Between C \'s \'Undefined Behavior\' and \'Ill-Formed; No Diagnostic Required\'?

What\'s the Difference Between C \'s \'Undefined Behavior\' and \'Ill-Formed; No Diagnostic Required\'?

Barbara Streisand
Release: 2024-11-21 12:40:16
Original
658 people have browsed it

What's the Difference Between C  's

Difference Between Undefined Behavior and Ill-Formed: No Diagnostic Required

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.

Definitions

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.

The Case of "ill-formed; no diagnostic required"

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.

Distinguishing from Undefined Behavior

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.

Impact on Compilation and Execution

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.

Consistency Issues

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.

Conclusion

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template