"Bartc" <bc@freeuk.comw rites:
"Ben Bacarisse" <ben.usenet@bsb .me.ukwrote in message
news:87d4oc7i1f .fsf@bsb.me.uk. ..
>
>
>>
>Not everyone will expect the same thing!
>>
>>
>Of course it can. The behaviour is undefined so it may check (or not
>check) anything it likes in this case. What has the emphasis of this
>group got to do with what a standard library function does?
>
Something to do with setting an example?
news:87d4oc7i1f .fsf@bsb.me.uk. ..
>"Bartc" <bc@freeuk.comw rites:
>>status=fclose (0);
>>crashes on the first two implementations I tried. Then I tried DMC and
>>that
>>gave the expected EOF status.
>>that
>>gave the expected EOF status.
>Not everyone will expect the same thing!
>>
>>Given the emphasis on error-checking in this group, it seems astonishing
>>that a library function (executed at most once per file) cannot do this
>>elementary check on it's parameter.
>>that a library function (executed at most once per file) cannot do this
>>elementary check on it's parameter.
>Of course it can. The behaviour is undefined so it may check (or not
>check) anything it likes in this case. What has the emphasis of this
>group got to do with what a standard library function does?
Something to do with setting an example?
you are surprised by how keen we are on error checking, given how lax
the library is? I don't know, but I don't think that is your main
point.
Anyway, I don't think there *is* an emphasis on functions checking their
input. There certainly is on checking the results, but that is not
the same. I think most regulars here will have caught the C bug of
doing rather minimal checking *in* a function. See, for example, the
recent posts about K&R solutions -- most of the examples posted ensure
that a function is called correctly and don't re-check inside.
If a writer of a library function can't check a handle (for a common error
like NULL, in a non-speed-critical function) why should anybody else?
>
>
I know about null string pointers. I'd prefer the library to be tolerant of
them.
like NULL, in a non-speed-critical function) why should anybody else?
>
>It's normal. Have you tried strlen(0), strcpy(0, 0) or fopen(0, 0)?
I know about null string pointers. I'd prefer the library to be tolerant of
them.
>Luck is another matter. In a way you were lucky that at least one
>implementati on flagged up the call (with a crash). If you'd used one
>that just returns EOF (which is allowed), you'd have no warning that
>the construct is not portable.
>implementati on flagged up the call (with a crash). If you'd used one
>that just returns EOF (which is allowed), you'd have no warning that
>the construct is not portable.
That's true. And if I did have a file that needed closing then fclose(0)
returning EOF wouldn't tell me there was a problem (although I would find
out in due course).
>
But then, it may crash quietly.
>
What's wrong with fclose() doing something like: "ABORTING: Invalid handle
to fclose()".
write error messages. I don't think it is forbidden, it is just not
expected (at least on the systems I am used to).
--
Ben.
Leave a comment: