putw return value

Guy Harris guy at sun.uucp
Thu Sep 18 04:42:41 AEST 1986

> Question:  What should "putw" return?
> Our I/O library returns the error code for the "putw" operation, which is
> usually 0.   In perusing BSD4.2 and ATT5.2.2 source, I see the same 
> functionality.

Which probably means it predates both of them, and worked that way in the
V7-vintage standard I/O library.  This would indicate it's probably supposed

> Yet the man pages seem to indicate that "putw" should return the "word"
> written.

The trouble with returning the value written is that if you write the value
-1, this can't be distinguished from EOF (at least on UNIX implementations,
and others where EOF is -1), and unless you *know* that you won't be writing
that value, you have to call "ferror" on that stream to detect errors.

> Is there a discrepancy between the code and the documentation?

Well, if there isn't, how do you explain the fact that the code and
documentation disagree?  More likely, you meant "There is a discrepancy
between the code and the documentation; which is correct?" to which the
answer is, most likely, "The code, in this case; the code has been that way
for a long time, though several variations of UNIX, and 'fixing' it to agree
with the documentation would cause other problems."

> (The Perennial C test suite makes mention in a "bugs" section that the
> VAX 11/750 also returns "0" for putw in the particular test.)

Which is a very odd way of putting it; did the people who did that test
suite to work differently on a VAX-11/780, for instance?
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)

More information about the Comp.lang.c mailing list