Defect Report #135

Submission Date: 31 Jan 94
Submittor: Project Editor (P.J. Plauger)
Source: Per Bothner
H.J. Lu points out that the SVR4 manual explicitly says that fwrite(ptr, 0, 1, stream) returns 0, not 1. I don't know what the SVID states.
I think it is more mathematically consistent to return 1 in this case. But in that case fread(ptr, 0, 1, stream) should also return 1, but ANSI explicitly states that it should return 0. I don't see any reason why these should be different, so I think it is best to follow existing practice. I think the ANSI specification for fwrite is a mistake; perhaps it should be fixed in the revision.
There are no zero-length objects in C. Therefore, if the size argument to fwrite is zero, it is outside the domain of the function and (by subclause 7.1.7), the result is undefined. The C Standard is not in conflict with the cited behavior of SVR4.
Previous Defect Report < - > Next Defect Report