news.volyx.in

Everything in C is undefined behavior (blog.habets.se)

505 points by lycopodiopsida · 101 days ago · 718 comments on HN

Article summary

The article discusses how everything in C is undefined behavior, citing various examples of subtle and illogical undefined behavior in the language. The author argues that even experienced programmers can't write correct C code and that the language's age and complexity make it difficult to avoid undefined behavior. The article also mentions the use of Large Language Models (LLMs) to detect undefined behavior in code. The author concludes that writing C or C++ without LLM supervision should be considered irresponsible.

Main themes

  • Undefined Behavior in C
  • C Standard Complexity
  • LLM-based Code Analysis
  • Compiler Optimization
  • Programming Language Safety
  • Code Correctness

What commenters say

  • Some argue that certain casts in C are valid and do not result in undefined behavior, while others claim that such casts can lead to undefined behavior.
  • The C standard's definition of undefined behavior is too broad and allows compilers to exploit it in unintended ways.
  • Others believe that the standard's definition is necessary to allow for optimization and that programmers should be aware of the potential pitfalls.
  • There is a need to codify a pragmatic subset of C that works on modern CPUs, as the current standard is outdated and prone to undefined behavior.
  • Some argue that prohibiting time-traveling undefined behavior would be beneficial, while others believe it would hinder optimization techniques like dead code elimination.
  • The use of LLMs to detect undefined behavior is seen as a necessary step to ensure code correctness, given the complexity of the C language.
  • The discussion highlights the importance of understanding the intent behind the C standard's definition of undefined behavior, rather than interpreting it in a purely legalistic manner.