DevNotes/src/20240312105610.md

1.1 KiB

title description date id taxonomies references license
Undefined behavior 2024-03-12 20240312105610
categories tags
development
https://en.m.wikipedia.org/wiki/Undefined_behavior
CC0-1.0

In computer programming, undefined behavior (UB) is the result of executing a program whose behavior is prescribed to be unpredictable, in the language specification to which the computer code adheres.

the cases for undefined behavior typically represent unambiguous bugs in the code, for example indexing an array outside of its bounds.

It is the responsibility of the programmer to write code that never invokes undefined behavior, although compiler implementations are allowed to issue diagnostics when this happens.

Undefined behavior can result in a program crash or even in failures that are harder to detect and make the program look like it is working normally, such as silent loss of data and production of incorrect results.

In general, any instance of undefined behavior leaves the abstract execution machine in an unknown state, and causes the behavior of the entire program to be undefined.