Undefined Behavior in C Can Make a Function You Never Called Run

Attention people who think UB is fine

A follow-up to an earlier post on undefined behavior in C, this time with compiler output to prove the skeptics wrong. Trigger UB in the same spot and GCC and Clang do wildly different things: one emits an uncalled function's code, another writes zero instead of 99 to address zero and then crashes on an invalid instruction, and a third case does exactly what the source says. The lesson: UB does anything.

I have now demonstrated three things UB can do, when UB was triggered in the same place: run whatever happens to be next in memory, store a random value at address zero and then deliberately crash, or do what one would naively expect.

More from this day

2026-10-25