I don't understand why sometimes I need to use fflush() and sometimes not.
My program is segfaulting at the moment and I am debugging it with print statements. When a program segfaults, does stdout not flush its buffer automatically?
I don't understand why sometimes I need to use fflush() and sometimes not.
Sometimes the stdio buffers are flushed sometimes they aren't. For example simply including a "\n" in the printed stuff will typically flush it (because stdout is by default line-buffered when attached to a terminal).
When a program segfaults, does stdout not flush its buffer automatically ?
Stdio buffers are flushed by exit. When a signal (such as SIGSEGV) kills a process, exit is not called. Another way to exit a process without flushing the stdio buffers is to use the Unix-specific call _exit.
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