casts to (void) [in particular, (void) printf (...)]

Roy Smith roy at phri.UUCP
Fri Aug 9 06:20:04 AEST 1985


[ assorted babble about (void) hiding printf(3S) errors leading to the
observation that printf doesn't return any kind of error status]

> [...] printf(3) calls the system call write(2).  If sucessful, the return
> value is set to the number of characters written, else -1 is returned and
> errno is set to describe the error.

	Not quite.  Printf(3) calls putc(3) which (on most implementations)
is a macro which calls _flsbuf() (or something similar) when an internal
buffer gets full, which in turn eventually calls write(2).  The point is
that write(2) doesn't get called on every invocation of printf, so when
printf returns, the write errors have not yet happened.

	This behaviour is documented in the 4.2 manual page for putc, but
not in the Sys5 manual.  In either case, if you want to check for write
errors, printf is not the way to go.
-- 
Roy Smith <allegra!phri!roy>
System Administrator, Public Health Research Institute
455 First Avenue, New York, NY 10016



More information about the Comp.lang.c mailing list