CKTIS / C
undefined and unspecified behavior — concept C23
For undefined behavior the standard imposes no requirements; unspecified behavior chooses an allowed possibility, while implementation-defined behavior must be documented. A test must never depend on an observed UB result.
Version: C23
Syntax
undefined and unspecified behaviorFor undefined behavior the standard imposes no requirements; unspecified behavior chooses an allowed possibility, while implementation-defined behavior must be documented. A test must never depend on an observed UB result.
Treat every UB warning as a design defect: check divisor, range, lifetime, and object bounds before the operation. If wrapping is required, use an unsigned type; if an object representation must be copied, use permitted character access or memcpy.
The same program with UB may appear to work in debug, change result under optimization, or lose a check the compiler considers unreachable. Unspecified behavior, such as some evaluation orders, requires code valid for every permitted choice; implementation-defined behavior must be tied to target documentation.
Examples
#include <limits.h>
#include <stdio.h>
int main(void) { unsigned value = UINT_MAX; value += 1u; printf("%u\n", value); return 0; }
Result
0
For undefined behavior the standard imposes no requirements; unspecified behavior chooses an allowed possibility, while implementation-defined behavior must be documented. A test must never depend on an observed UB result.