3 ms·
I think the author does want fread() to overwrite N-1 bytes, iff there are N-1 bytes to read. The objection is to overwriting N-1 bytes when only N-2 bytes wer
by Karellen 4y ago
I think the author does want fread() to overwrite N-1 bytes, iff there are N-1 bytes to read.
The objection is to overwriting N-1 bytes when only N-2 bytes were read.
Which... doesn't sound completely unreasonable?
On the other hand (especially with SIMD CPUs, but maybe also with simpler instruction sets) I can understand that copying blocks of e.g. 8 bytes at a time might be faster than the special case at the end of a read for copying only 7 bytes. (Because you need to follow an "unlikely" branch to get to the 7-byte code which stalls the CPU, maybe.) So if the output buffer has space for it, it might be more performant to copy 8 bytes including a junk byte and just say you copied 7, than copying only 7 bytes.
And the author does seem to object to a number of other design decisions which could hurt performance.