c - “语义违规不需要诊断”的理由是什么?
问题描述
后续问题:如果违反了“应/不应”要求,那么该要求位于哪个部分(例如语义、约束)是否重要?.
ISO/IEC 9899:202x (E) 工作草案——2020 年 12 月 11 日 N2596,5.1.1.3 诊断,1:
如果预处理翻译单元或翻译单元包含违反任何语法规则或约束的行为,则符合的实现应产生至少一个诊断消息(以实现定义的方式标识),即使该行为也明确指定为未定义或实现-定义。在其他情况下不需要生成诊断消息。
结果:语义违规不需要诊断。
问题:“语义违规不需要诊断”的(可能)理由是什么?
解决方案
A possible rationale is given by Rice's theorem : non-trivial semantic properties of programs are undecidable
For example, division by zero is a semantics violation; and you cannot decide, by static analysis alone of the C source code, that it won't happen...
A standard cannot require total detection of such undefined behavior, even if of course some tools (e.g. Frama-C) are sometimes capable of detecting them.
See also the halting problem. You should not expect a C compiler to solve it!
推荐阅读
- jquery - 为什么数据表排序不能在正确的地方工作?
- android - How can I make the mock location provider to work
- python - 设计一个 should_throttle 函数,限制基于特定时间窗口内的请求
- c# - DataGridTextColumn Header 的绑定不起作用
- java - Spring Reactor:Optional 对应的类是什么
? - c# - 在 RaiseAndSetIfChanged 中吞下异常
- javascript - 如何对动态创建的输入字段中的值求和
- simulator - Ns3 getdeconds() 问题。使用此函数获取时间延迟但失败
- xml - Xpath current() in Yang
- c++ - 安全地引用具有与模板不兼容的模板参数的 C++ 模板类型?