Re: A question regarding Q20.1 from c-faq.com
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 19 Dec 2007 11:51:16 -0800
santosh <santosh.k83@xxxxxxxxx> writes:
[...]
The intent of the Standard was for an EOF return to indicate end-of-file[...]
or error.
7.19.1 (3)
EOF
which expands to an integer constant expression, with type int and a
negative value, that is returned by several functions to indicate
end-of-file, that is, no more input from a stream;
<<<<<
The only sensible way to deal with character based I/O on systems where
UCHAR_MAX > INT_MAX is to use functions customised for the platform.
But such customized functions aren't necessary. The usual idiom of
``while ((c = getchar()) != EOF)'' won't work properly on such
systems, but the workaround (checking feof() and ferror() after
getting an EOF result) solves the problem for exotic systems with
UCHAR_MAX > INT_MAX *and* works properly on ordinary systems.
It certainly would have been nice if the common idiom, which works on
almost all systems, were actually guaranteed by the standard to work
on all systems, but we're stuck with the current situation.
And I suspect that there are no *hosted* implementations with
UCHAR_MAX > INT_MAX. Non-hosted (freestanding) implementations aren't
even required to support <stdio.h>, and if they do support it it
needn't conform to the standard's requirements (though as a QoI issue
it should). Adding a requirement for sizeof(int) > 1 for hosted
implementations would largely solve the problem and *probably*
wouldn't affect any real-world implementations.
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: A question regarding Q20.1 from c-faq.com
- From: Richard Tobin
- Re: A question regarding Q20.1 from c-faq.com
- References:
- A question regarding Q20.1 from c-faq.com
- From: Logan Lee
- Re: A question regarding Q20.1 from c-faq.com
- From: Mark McIntyre
- Re: A question regarding Q20.1 from c-faq.com
- From: Peter Nilsson
- Re: A question regarding Q20.1 from c-faq.com
- From: santosh
- Re: A question regarding Q20.1 from c-faq.com
- From: santosh
- Re: A question regarding Q20.1 from c-faq.com
- From: Mark McIntyre
- Re: A question regarding Q20.1 from c-faq.com
- From: Mark McIntyre
- Re: A question regarding Q20.1 from c-faq.com
- From: jameskuyper
- Re: A question regarding Q20.1 from c-faq.com
- From: Mark McIntyre
- Re: A question regarding Q20.1 from c-faq.com
- From: James Kuyper
- Re: A question regarding Q20.1 from c-faq.com
- From: santosh
- A question regarding Q20.1 from c-faq.com
- Prev by Date: Re: Positive random number
- Next by Date: Re: Annoying compiler warning
- Previous by thread: Re: A question regarding Q20.1 from c-faq.com
- Next by thread: Re: A question regarding Q20.1 from c-faq.com
- Index(es):
Relevant Pages
|