fwrite(buf, 0, 42, stream) == ?

Felix Lee flee at psuvax1.cs.psu.edu
Thu Jun 14 13:18:03 AEST 1990


Doug Gwyn wrote:
>Strictly speaking, there are no semantics defined for such usage,

Well, does that mean it's undefined or implementation defined?  If the
standard defines malloc(0), why not fwrite(p, 0, n, stream)?

The reason I asked, it was natural for me to write a substring with
a)	if (fwrite(p, end - p, 1, stream) < 1) return ERR;
which runs into problems when p == end.

The alternative
b)	if (fwrite(p, 1, end - p, stream) < end - p) return ERR;
also has problems when p == end, since you can't distinguish failure
from success.

I have to use something like
c)	if (p < end && fwrite(p, end - p, 1, stream) < 1) return ERR;
or
d)	if (p < end && fwrite(p, 1, end - p, stream) < end - p) return ERR;

Somehow, I liked (a) best.  Failing that, I'm using (c).

Urmf.  If sizeof(char [n]) != n, then I can't use (c) either.
--
Felix Lee	flee at cs.psu.edu



More information about the Comp.std.c mailing list