1

Does ferror() aggregate all errors of previous fputc(stdout), fputs(stdout), putc(stdout), putchar or puts calls?

At least when not using wide strings?.. (Nor printf().)

If it does then may it be an error checking strategy to check for errors only at the end of a series of putc-like calls? (Otherwise using ferror() and the stream's error indicator flag seem to be redundant...)


(Edit)

Is this question already answered??..

If so, please help: yes or no is the answer?

Do I have to check each and every return value of fputc(stdout) et al or not? (If I do not want to catch errors early, it is enough to detect errors after a couple of output operations.)

I surely know (knew) that some sort of errors cause setting the stream's error flag. The question was that whether all errors (any error that causes fputc etc. return negative) sets the stream's error flag.

  • 1
    What do you mean by "aggregate"? Once a stream enters an error state, it's stuck there. – molbdnilo Nov 20 '17 at 13:56
  • 1
    If an error occurs writing to standard output, `ferror()` will continue to report that until you clear the error (`clearerr()`) or close the file stream. If that’s "aggregation" then errors are aggregated. – Jonathan Leffler Nov 20 '17 at 13:59
  • 1
    Just be sure your sequence of writes isn't really huge - nobody wants to wait for a terabyte to be written to a failing stream, even if the failure is correctly reported afterward –  Nov 20 '17 at 14:02
  • Notice that for example `fwrite`s might be short/partial too... – Antti Haapala -- Слава Україні Nov 20 '17 at 15:04

0 Answers0