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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sometimes the
stdiobuffers are flushed sometimes they aren’t. For example simply including a “\n” in the printed stuff will typically flush it (becausestdoutis by default line-buffered when attached to a terminal).Stdio buffers are flushed by
exit. When a signal (such asSIGSEGV) kills a process,exitis not called. Another way to exit a process without flushing thestdiobuffers is to use the Unix-specific call_exit.