Re: A question regarding Q20.1 from c-faq.com



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"
.



Relevant Pages

  • Re: replacing X Window System !
    ... just with some implementations. ... interface or most inter-application communication. ... Lack of application support (which requires backwards compatibility) is ...
    (Linux-Kernel)
  • Re: WHY doesnt C know anything about directories?
    ... typically have freestanding C implementations (as opposed to hosted ... A conforming freestanding implementation needn't ... support most of the standard headers at all. ... It turns out to be a lot easier to define a portable file interface ...
    (comp.lang.c)
  • Re: Assuming size_t is unsigned long
    ... It's probably best put in a helper function, ... (This will not work for implementations that use C99 syntax with a C90 ... systems, printf will support "%zu"; on others, it won't, and gcc won't ... C99 *discourages*, but does not forbid, making size_t bigger than ...
    (comp.lang.c)
  • Re: Alias GF and rotate arguments
    ... implementations are not consistent in support the argument lists for ... make-method-lambda is almost non-existent. ... appears to work) in a few implementations without resorting to make- ... (funcall method-function (reverse x) ...
    (comp.lang.lisp)
  • Re: How to get the object method name?
    ... I don't know about JScript and other implementations, ... one would need to get the stack trace in the script that is debugged. ... the console.logcall I assume you use or at least support Firebug, ... provides the stack trace along with the error message. ...
    (comp.lang.javascript)