On this page
  1. Undefined Behavior & Sanitizers
  2. Contents
  3. High-Frequency Undefined Behavior (UB) Traps
  4. Essential Compiler Flags & Sanitizers

Undefined Behavior & Sanitizers

Prev: Function Pointers & Callbacks | Up: pointers_and_memory | Next: stdlib
Rel: Dynamic Memory & Allocators, Build Pipeline & Linking
Ref: cppreference — Undefined Behavior
Tags: #public #prog #c #memory #safety #sanitizers


Contents


High-Frequency Undefined Behavior (UB) Traps

When a C program triggers Undefined Behavior, the compiler is permitted to assume it never happens — silently deleting checks or corrupting memory:


Essential Compiler Flags & Sanitizers

Always develop and test with warnings + AddressSanitizer (ASan) + UndefinedBehaviorSanitizer (UBSan):

cc -std=c17 -g -O1 -Wall -Wextra -Wpedantic -Werror \
   -fsanitize=address,undefined main.c -o main

Linked from

Related notes