Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M1048

Undefined Behavior / UB

Undefined Behavior / UB
BehaviorHigh supportPsychology
Included
account_tree

Version 1.0.0 · Updated 2026-07-28

CORE DEFINITION

In computer programming, undefined behavior refers to the result of executing certain computer code whose behavior, in the current program state, is not specified by the language standard. It commonly occurs when a translator (compiler) makes certain assumptions about the source code, and these assumptions do not hold at runtime. Some programming languages have undefined behavior in certain situations, most notably C and C++. In the standards of these languages, the semantics of certain operations are defined as undefined, typical examples being program errors such as out-of-bounds array access. The standard allows a specific implementation of the language to assume that any conforming program will not exhibit such behavior. Specifically in C/C++, the compiler may optionally issue a diagnostic, but it is not required to: for undefined behavior, any reaction by the language implementation is considered correct, similar to don't-care terms in digital logic. Although compiler implementations may issue diagnostics for undefined behavior, it is the programmer's responsibility to ensure that the code they write does not trigger undefined behavior.

SCAFFOLDING EFFECT

psychology

Reduce cognitive load

In computer programming, undefined behavior refers to the result of executing certain computer code whose behavior, in the current program state, is not specified by the language standard. It commonly occurs when a translator (compiler) makes certain assumptions about the source code, and these assumptions do not hold at runtime. Some programming languages have undefined behavior in certain situations, most notably C and C++.

anchor

Anchor fast decisions

In programming languages, operations whose results are not specified by the standard (such as null pointer dereference, signed overflow) are called undefined behavior (UB). The compiler may assume that they do not occur and perform aggressive optimizations based on that. The mechanism is that the standard leaves gaps to allow for optimization.

MINIMUM ACTION

In progress 0/3

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%
account_treeGenealogyexpand_more
menu_bookReferencesexpand_more

Source support: Explicit

  • link
    zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E6%9C%AA%E5%AE%9A%E4%B9%89%E8%A1%8C%E4%B8%BAZH · Explicit
    verified

RELATED MODELS