3 ms·
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
by omgJustTest 2y ago
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.
- dennis_moore 2y agoAh yes, it can be quite fun chasing down heisenbugs like that, half sarcastically :)