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.
Activity Over Time
Top Contributors
Keywords
Sample Comments
UB = "undefined behavior", thanks
Undefined behavior: https://en.m.wikipedia.org/wiki/Undefined_behavior
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
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
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."
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.
That's not what undefined behavior means.
That's not what undefined behavior means.
That is called unspecified behavior not undefined behavior. Major difference.
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.