Hi Collin,

> The mb_putc function in mbchar.h is defined as:
> 
>     #define mb_putc(mbc, stream)  fwrite ((mbc).ptr, 1, (mbc).bytes, (stream))
> 
> but documented as:
> 
>     extern void           mb_putc (const mbchar_t mbc, FILE *stream);
> 
> If someone wanted to check that the character was written, they could
> check the that the return value of the fwrite is correct, equal to
> mb_len (mbc).

Marking the return type of mb_putc as 'void' is intended, to match the
common use of fputc() and putc(). Most programs that use stdio for output
don't check the return value of fputc(), putc(), fwrite(), fprintf(),
since it is easier to write the error handling in one place, through an
ferror() test, rather than to litter the code with '== EOF' tests and error
handling. (And the cases where fprintf() can fail without setting the stream's
error indicator are such that most programs don't encounter them: when dealing
with wide characters or huge strings.)

Thus, it wouldn't make sense to encourage people to test a return value of
mb_putc().

This is a particular instance of "it's better to offer one way, not two or
more ways, to do a specific thing". Because if there are several ways, the
decision which one to use eats up brain cycles of the programmer. This is the
C++ trap: The C++ language and the C++ APIs often offer multiple ways to do
the same thing.

Bruno




Reply via email to