Path: 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: Date: 14 Jun 90 03:18:03 GMT References: <13094@smoke.BRL.MIL> Sender: news@cs.psu.edu (Usenet) Organization: Penn State Computer Science Lines: 25 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