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

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Jun 15 04:46:05 AEST 1990


In article <F.-&asi at cs.psu.edu> flee at psuvax1.cs.psu.edu (Felix Lee) writes:
>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)?

It doesn't define semantics for malloc(0) either, for exactly the same
reason (the argument is the size of an object, and there are no zero-
sized objects).  The only requirement is that malloc() return either a
pointer to at least zero bytes of (distinguishable) allocated storage
or that it return a NULL pointer; the implementation may choose to do
the latter.

As POC for the zero-sized object extensions special interest group,
I would be happier if semantics for dealing with zero-sized objects
had been included in the standard, but a deliberate decision was made
to outlaw them.

>Urmf.  If sizeof(char [n]) != n, then I can't use (c) either.

But sizeof(char[n]) is n, since the byte (char) is the basic unit of
storage in standard C and sizeof(char)==1 is a requirement.



More information about the Comp.std.c mailing list