In C++03 Standard observable behavior (1.9/6) includes calls to library I/O functions. Now I have this code:
printf( "" );
which is formally a call to a library I/O function but has no effect.
Is it observable behavior? Is the compiler allowed to eliminate it?
It's certainly observable if sync_with_stdio
is true
. When that's true, printf("")
forces synchronization with std::cout
output, flushing previously buffered output.
It would observable
The point made about sync_with_... is also very relevant
I highly doubt it, since the behavior might become more highly visible in multithreaded programming if the OS chooses to context switch when the thread invoking printf
blocks for I/O.
In that case, it will definitely have an effect if the results depend on how the threads is interleaved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With