What is "short item count" in fread()?
Asked Answered
W

2

12

When I was 'man fread', I got this:

RETURN VALUE
fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end- of-file is reached, the return value is a short item count (or zero).

fread() does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3) to determine which occurred.

So my question is to how to understand "short item count". Please bear with my English. Why here involves type "short"? Can you someone give an example of what does "short item count" look like? Thanks.

Wyeth answered 14/6, 2011 at 3:57 Comment(0)
E
6

If you want 4, and you have 3, then you're short 1.

Enactment answered 14/6, 2011 at 3:59 Comment(5)
If you want 4 and you have 3, fread will return 3. Where does the "short" come in? If the wording made any sense it would return 1. But that on the other hand, would be a nonsense API.Buskined
@Lundin: 3 is short compared to 4. The wording is fine.Enactment
You are 1 short, you are not 3 short. The English word short, in this context, can only refer to the number of missing items. An English-speaking person would assume that a "short item count" counts the amount of items that you are short. As opposed to a "successfully read items counter".Buskined
You are not 3 short, but the 3 is short.Enactment
Doesn't matter if grammatically this is correct or not. What matters is if anyone who is reading this description understands this or not. I am reading the fread man page for the first time, and I had to google to understand the meaning of this although my english is fine for a non-native speaker.Vickeyvicki
C
9

The meaning of "short" in fread man page does not refer to a data type.

"Short" in this case means "less then expected". If fread() expected to read 4 objects, but only read 3, it will return the value 3.

I believe that the the man page should be re-written to say: "If an error occurs, or the end-of-file is reached, the return value is the number of items successfully read or written up until the error or EOF occurred.

Cnidus answered 24/3, 2014 at 23:3 Comment(2)
Agree that the man page is badly written and needs to be rewritten. I know how fread works and I'm decent at English, yet I fail to understand it.Buskined
So, where do I submit a pull request to change this?Supervisor
E
6

If you want 4, and you have 3, then you're short 1.

Enactment answered 14/6, 2011 at 3:59 Comment(5)
If you want 4 and you have 3, fread will return 3. Where does the "short" come in? If the wording made any sense it would return 1. But that on the other hand, would be a nonsense API.Buskined
@Lundin: 3 is short compared to 4. The wording is fine.Enactment
You are 1 short, you are not 3 short. The English word short, in this context, can only refer to the number of missing items. An English-speaking person would assume that a "short item count" counts the amount of items that you are short. As opposed to a "successfully read items counter".Buskined
You are not 3 short, but the 3 is short.Enactment
Doesn't matter if grammatically this is correct or not. What matters is if anyone who is reading this description understands this or not. I am reading the fread man page for the first time, and I had to google to understand the meaning of this although my english is fine for a non-native speaker.Vickeyvicki

© 2022 - 2024 — McMap. All rights reserved.