Everything in C is undefined behavior

TL;DR

A prominent voice in the programming community asserts that all nontrivial C code contains undefined behavior (UB). This challenges assumptions about safety and correctness in C programming today. The statement underscores widespread issues with language design and compiler assumptions.

A veteran programmer and industry analyst has declared that every nontrivial C program contains some form of undefined behavior, emphasizing the pervasiveness of this issue in 2026. This assertion underscores ongoing concerns about the safety, correctness, and portability of C code, which remains foundational in many systems.

The statement originates from a detailed critique of C and C++, highlighting how modern code invariably involves undefined behavior (UB). The speaker, who has extensive experience with C and C++ over 30 years, points out that common mistakes—such as memory corruption, misaligned access, or incorrect casting—are not just bugs but are often classified as UB by the language standards.

They clarify that UB is not solely about compiler optimizations but fundamentally about the language’s design, which allows many operations to be undefined. For example, dereferencing unaligned pointers or casting pointers to incompatible types can be UB, regardless of whether the code is optimized or not. Such issues are widespread, affecting even seemingly simple code snippets, and are often invisible to programmers until they cause crashes or security vulnerabilities.

The speaker emphasizes that different hardware architectures handle UB differently—some trap, crash, or emulate operations, while others, like x86, may appear to work fine. However, this variability does not negate the fact that the behavior is undefined by the standard and can change unpredictably with compiler updates or hardware changes.

They also highlight that certain operations, such as atomic loads on misaligned data, are UB, and that even creating pointers with incorrect alignment or casting raw byte buffers to typed pointers can trigger UB. This ubiquity makes it impossible to write truly portable, bug-free C code, according to the speaker.

Why It Matters

This statement matters because it challenges long-held assumptions about C’s safety and portability, especially in critical systems. If all nontrivial C code involves UB, then many existing programs may be inherently unreliable or vulnerable to future compiler or hardware changes. It raises questions about the suitability of C for safety-critical applications and suggests a need to reconsider language choices or adopt stricter coding standards.

Furthermore, this critique could accelerate efforts to develop safer programming languages or tools that can better manage or eliminate UB, impacting the future of systems programming.

Rust for C Engineers: Safe Systems Programming

Rust for C Engineers: Safe Systems Programming

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Background

C has been the dominant systems programming language since its creation in the early 1970s. Over decades, developers have been aware of certain UB issues, such as use-after-free or buffer overflows, but the scope of UB has expanded with language standards and compiler optimizations. Recent discussions, including prominent industry voices, have increasingly highlighted that UB is not just about specific bugs but an inherent feature of the language’s design.

The current debate echoes past concerns about C’s safety, but the recent statement emphasizes that UB is unavoidable and omnipresent in nontrivial code, making the language fundamentally less safe than often assumed.

“Every nontrivial C program involves some form of undefined behavior, and this is a systemic issue embedded in the language’s design.”

— Veteran programmer and industry analyst

“UB means the compiler can assume your code is valid, which leads to unpredictable behavior and security risks.”

— Language standards expert

Advanced C++ Memory Techniques: Efficiency and Safety (Advanced C++ Programming Book 5)

Advanced C++ Memory Techniques: Efficiency and Safety (Advanced C++ Programming Book 5)

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

What Remains Unclear

It remains unclear whether this statement reflects a consensus view or an extreme interpretation. The extent to which all C code is practically affected by UB, and how this impacts existing codebases, is still being discussed. Additionally, the precise implications for safety-critical systems are not yet fully explored.

Amazon

C language static analyzers

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

What’s Next

Expect increased scrutiny of C code in industry, with potential shifts toward safer languages or stricter coding standards. Tooling and compiler warnings may evolve to better detect or mitigate UB. Ongoing discussions will likely explore how to address or manage the pervasive presence of UB in C programming.

1Pc only not like pic shown Optical Lab Alignment Tool Optical Path Debugging Disc, Coaxial System with SM05 SM1 External Thread Alignment Plate (ZAB-SM1 with SM1 external thread)

1Pc only not like pic shown Optical Lab Alignment Tool Optical Path Debugging Disc, Coaxial System with SM05 SM1 External Thread Alignment Plate (ZAB-SM1 with SM1 external thread)

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Key Questions

Does this mean all C code is unsafe?

Not necessarily unsafe in practice, but according to the statement, all nontrivial C code contains some form of undefined behavior, which can lead to unpredictable results or vulnerabilities.

Can we still write correct C programs?

Yes, but it requires careful coding, understanding of UB, and adherence to strict standards. Complete elimination of UB in complex code is effectively impossible.

What are the implications for safety-critical systems?

This raises concerns about relying on C for safety-critical applications, as UB can cause unpredictable failures or security issues. Alternatives or additional safety measures may be necessary.

Will compilers change to prevent UB?

While some tools warn about UB, the language standard itself allows it. Future compiler developments may attempt to mitigate UB, but the fundamental issue stems from language design.

Source: Hacker News

You May Also Like

MCP Hello Page

HybridLogic introduces a new MCP server feature to improve user onboarding by displaying helpful HTML messages, reducing support tickets and confusion.

Why State Management Still Confuses Frontend Teams

Absolutely, mastering state management remains challenging because understanding how data flows and components sync is complex; keep reading to uncover effective solutions.

Kubernetes for Beginners: Container Orchestration Simplified

Navigating the world of container orchestration can be complex, but Kubernetes for beginners makes it simple—discover how it transforms your deployment process.

GitHub and the crime against software

GitHub faces ongoing outages, security issues, and reliability failures, raising concerns about its role in modern software infrastructure and trust.