News for hackers. Stuff that matters.
Re:Printf debugging is ok by omgJustTest on Monday January 06, 2025 @12:19AM (#42607914)
An interesting note: printf'ing a variable can sometimes alter how a variable is cached. This is a particularly useful fact in memory locations that can change as a result of hardware operations (like a change of a status bit by a hardware element).

printf'ing effectively enforces a similar condition to `volatile` on the underlying memory segment when it is read.

One can encounter tersely written code that works perfectly with printf statements, but status bits never get "updated" (CPU cache purged) without the printf and hangs the program.

Re:Printf debugging is ok by dennis_moore on Monday January 06, 2025 @12:59AM (#42608096)
Ah yes, it can be quite fun chasing down heisenbugs like that, half sarcastically :)