🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1428

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

#1428
From: Felix Lee
Date: Thu, 14 Jun 1990 03:18
25 lines
1338 bytes
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@cs.psu.edu
Technical Details
Message-ID: <F.-&asi@cs.psu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!psuvax1!news
References: <Fkucoph@cs.psu.edu> <13094@smoke.BRL.MIL>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!psuvax1!news
From: flee@psuvax1.cs.psu.edu (Felix Lee)
Newsgroups: comp.std.c
Subject: Re: fwrite(buf, 0, 42, stream) == ?
Message-ID: <F.-&asi@cs.psu.edu>
Date: 14 Jun 90 03:18:03 GMT
References: <Fkucoph@cs.psu.edu> <13094@smoke.BRL.MIL>
Sender: news@cs.psu.edu (Usenet)
Organization: Penn State Computer Science
Lines: 25