From: Florian Weimer <fweimer@redhat.com>
To: Peng Yu via Libc-help <libc-help@sourceware.org>
Subject: Re: EOF is a misnomer?
Date: Tue, 11 May 2021 15:42:47 +0200 [thread overview]
Message-ID: <87bl9h1j54.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CABrM6wk_Y-Xff+=ZwHZjm-LMkFuG2OpQG9rzkLfp_c3qnX9D3Q@mail.gmail.com> (Peng Yu via Libc-help's message of "Tue, 11 May 2021 08:27:46 -0500")
* Peng Yu via Libc-help:
> man getchar says
>
> " fgetc(), getc(), and getchar() return the character read as an unsigned
> char cast to an int or EOF on end of file or error."
>
> EOF literally stands for end of file. But the above functions can
> return EOF when there is an error.
>
> In feof(), "eof" just means end of file as shown in man feof.
>
> The function feof() tests the end-of-file indicator for the stream
> pointed to by stream, returning nonzero if it is set. The end-of-file
> indicator can be cleared only by the function clearer().
>
> So the macro name EOF is a misnomer. It could have been named as
> something like EOF_OR_ERR? The fact that its name is EOF is due to
> some historical reasons? Thanks.
It's this way for historical reasons. EOF can also be a valid character
(if sizeof (int) is 1, as permitted by the C standard), so the whole
interface is a bit questionable.
Thanks,
Florian
prev parent reply other threads:[~2021-05-11 13:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-11 13:27 Peng Yu
2021-05-11 13:38 ` Konstantin Kharlamov
2021-05-11 14:11 ` Peng Yu
2021-05-11 13:42 ` Florian Weimer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bl9h1j54.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-help@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).