Very frequently, I want to test the value of a variable in a function via a breakpoint. In many cases, that variable never actually gets referenced by any code that “does stuff”, but that doesn’t mean I don’t still want to see it. Unfortunately, the optimizer is working against me and simply removing all such code when compiling, so I have to come up with convoluted grossness to fool the compiler into thinking those values actually matter so they don’t get optimized away. I don’t want to turn the optimizer off, as it’s doing important stuff in other places, but just for this one block of code I’d like to temporarily disable it for the sake of debugging.
Share
Code the produces observable behavior fits the requirements by definition. For example,
printf("").Access to volatile variable also formally constitutes observable behavior, although I won’t be surprised if some compilers still discarded “unnecessary” volatile variables.
For this reason, a call to an I/O function appears to be the best canditate to me.