If you use stderr, you get this for free: stderr is always unbuffered (see <a href="https://linux.die.net/man/3/stderr" rel="nofollow">https://linux.die.net/man/3/stderr</a>).
In C++, I've absolutely had to explicitly use std::endl while debugging to make sure that my debug messages actually were visible when they were supposed to be. Using std::flush also works if you don't want to force a newline. However, in my experience, printing a newline character via std::cout does <i>not</i> flush the stream.
Am I right to claim C compiler could determine the NULL pointer dereference is an undefined behavior and do anything, like completely removing the dereference?
Somewhat similar, if you run program in new xterm with -hold parameter and it crashes, you won't see the segfault, you have to wrap it in parens.<p>xterm -hold -e './a.out' - no segfault<p>xterm -hold -e '(./a.out)' - will print segfault
You can also unbuffer stdout in a wrapper then exec your program. GNU-ish systems, including Linux, usually include a command called stdbuf that does this:<p><pre><code> stdbuf -i0 -o0 -e0 /some/command
</code></pre>
Where -i is for stdin, -o is for stdout, and -e is for stderr, and the number is the buffer size.