1. 6

  2. 5

    Here’s the abstract.

    If you develop in C and want an application to detect and diagnose output errors reliably, then you do NOT want to use the standard stream output functions like putchar, fputs, fprintf, etc. If you must use them anyway, there is a whole raft of corner cases you’ll have to worry about. Here, you’ll see how to deal with the ugly reality, while retaining some semblance of maintainability.

    Many programs write some or all of their output to stdout, the standard output stream. Yet, while most seasoned programmers realize the importance of closing (and diagnosing any failure therein) all files they open, few apply that discipline to stdout. The result is that many programs do not diagnose write errors. As you will see, although applications usually do not open stdout, it is often just as important to close it properly as it is to close any other output stream. I’ll illustrate the problem and show how to avoid it in a maintainable and minimally intrusive manner. While handling stdout has some subtle twists, you’ll see that using any output stream robustly requires great care, and in some cases it is next to impossible. In the end, you will be wondering why any developer who requires reliable output functions still uses C streams at all.