C Undefined Behavior

Cluster focuses on debates clarifying 'undefined behavior' (UB) in C/C++ standards, distinguishing it from implementation-defined and unspecified behaviors, and discussing its implications for compilers and code correctness.

📉 Falling 0.5x Programming Languages
3,565
Comments
19
Years Active
5
Top Authors
#1821
Topic ID

Activity Over Time

2008
4
2009
8
2010
18
2011
44
2012
61
2013
120
2014
112
2015
166
2016
278
2017
217
2018
228
2019
279
2020
266
2021
309
2022
387
2023
346
2024
366
2025
345
2026
11

Keywords

AFAIK e.g UB cppreference.com stddef.h wikipedia.org unistd.h en.m regehr.org ISO undefined undefined behavior behavior implementation defined ub compiler behaviour standard char

Sample Comments

cwmoore Sep 21, 2025 View on HN

UB = "undefined behavior", thanks

tyleo Jan 21, 2022 View on HN

Undefined behavior: https://en.m.wikipedia.org/wiki/Undefined_behavior

0xcde4c3db Jul 18, 2019 View on HN

Also, the specific phrase "undefined behavior" is typically invoked in a context related to the C programming language. In the C standard and some standards related to it, undefined behavior is just one point on a spectrum of (un)definedness:- implementation-defined: Not defined by the standard, but implementations must choose a consistent behavior and document it (e.g. what's shifted in when right-shifting signed integer types)- unspecified: Not defined by the standard; imp

rbehrends Jul 5, 2017 View on HN

This would not be what is called undefined behavior per the C standard, but unspecified or implementation-defined behavior. The bad thing about "undefined behavior" is that the implementation is basically allowed to do whatever it wants, while unspecified and implementation-defined behavior still has sane semantics. Unspecified behavior allows the language implementation to choose any one from several possible implementations, implementation-defined behavior requires the language imple

duped Oct 15, 2024 View on HN

That's implementation defined behavior, not undefined behavior. Undefined behavior explicitly refers to something the compiler does not provide a definition for, including "safe defaults."

david-gpu Feb 1, 2025 View on HN

LOL. No.Some languages/libraries even make an explicit distinction between Undefined and Implementation-Defined, where only the latter is documented on a vendor-by-vendor basis. Undefined Behavior will typically vary across vendors and even within versions or whatnot within the same vendor.The very engineers who implemented the code may be unaware of what may happen when different types of UB are triggered, because it is likely not even tested for.

ebingdom Apr 30, 2022 View on HN

That's not what undefined behavior means.

throwawaymaths Jul 25, 2023 View on HN

That's not what undefined behavior means.

just_curioussss Oct 24, 2015 View on HN

That is called unspecified behavior not undefined behavior. Major difference.

scott_s Nov 7, 2016 View on HN

I believe you are confusing undefined behavior and implementation defined behavior. Undefined behavior is illegal under all compilers, and all bets are off if you do it. Implementation defined behavior is always legal, but different compilers are allowed to do different things.