logoalt Hacker News

mort96today at 9:58 AM2 repliesview on HN

Wait, is that wrong? I always call fread as:

    fread(data, 1, sizeof(buffer), f);
with the rationale that I'm interested in reading sizeof(buffer) individual bytes. The buffer size is incidental, not the size of the items I'm trying to read from the file; "read one item whose size is sizeof(buffer)" seems semantically wrong.

Is this just the case of Windows having a bad stdlib fread implementation 15 years ago or is my thinking here actually wrong?


Replies

chadgpt3today at 10:13 AM

It's not wrong. Guy just wrote a bad implementation of fread and blamed everyone else.

show 1 reply
projektfutoday at 12:30 PM

fread should be buffered, but different values may cause buffering at different rates. Perhaps it didn't generate 65535 calls to ReadFile but it generated 16 or 64.