Re: A question regarding Q20.1 from c-faq.com
- From: jameskuyper@xxxxxxxxxxx
- Date: Tue, 18 Dec 2007 16:33:38 -0800 (PST)
Mark McIntyre wrote:
Richard Heathfield wrote:
Mark McIntyre said:
Richard Heathfield wrote:
santosh said:Yes but its obligated to mean that - since many functions are obligated
<snip>
I'm sure I'm missing something simple here, but to me, ifAll that this actually breaks is the assumption that a value of EOF
sizeof(char)==sizeof(int), it seems impossible to simultaneously return
all possible character values and the out-of-band value EOF.
necessarily means "it failed"
to return EOF on error conditions.
I agree that it means that - but where does the Standard say that it can
*only* mean that? :-)
Smiley noted. But since some functions are obligated to use EOF to
indicate an error, its completely correct to check for that return.
I would disagree; for the small set of routines where EOF is returned
through the same channel as valid characters, relying solely upon an
EOF value to diagnose an error/eof condition is the wrong approach,
unless the program tests to make sure that it does so only if
UCHAR_MAX < INT_MAX.
If in some implementations a programmer can't distinguish the error
return from a non-error return, ...
Since it's always possible to distinguish an error return from a non-
error return by use of ferr() and feof(), that's never an issue.
... code which is completely conforming will
malfunction. ...
There's no category named "completely conforming" defined by the
standard. The standard provides only two code-conformance categories;
one of which ("conforming code") is far too broad to be of any use
whatsoever, other than being a political compromise that allowed the
standard to be approved. The other category ("strictly conforming
code") is far too strict to describe any significant fraction of real-
world programs; it's useful for discussing the meaning of the
standard's requirements, but not for much else. However, what we're
doing right now is discussing the meaning of the standard's
requirements, so that's the term I'll assume you're referring to.
A program that is "strictly conforming", is prohibited from producing
output which depends upon implementation-defined behavior. Code such
as you describe has behavior which depends upon whether or not
UCHAR_MAX > INT_MAX, which is implementation-defined. If that behavior
has any visible effect on the output of the program, then the code is
not strictly conforming.
... My POV is that if an implementation can't translate and
_execute_ a conforming programme correctly, it can't be a properly
conforming implementation.
I believe that a conforming implementation of C with UCHAR_MAX >
INT_MAX could translate and execute a program such as you describe
correctly; it wouldn't behave as intended by the developer, but it
would behave in a manner which is completely consistent with the
standard's requirements for the behavior of such code.
.
- Follow-Ups:
- Re: A question regarding Q20.1 from c-faq.com
- From: Mark McIntyre
- 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: Walter Roberson
- Re: A question regarding Q20.1 from c-faq.com
- From: Peter Nilsson
- 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
- Re: A question regarding Q20.1 from c-faq.com
- From: Richard Heathfield
- Re: A question regarding Q20.1 from c-faq.com
- From: santosh
- Re: A question regarding Q20.1 from c-faq.com
- From: Richard Heathfield
- Re: A question regarding Q20.1 from c-faq.com
- From: Mark McIntyre
- Re: A question regarding Q20.1 from c-faq.com
- From: Richard Heathfield
- Re: A question regarding Q20.1 from c-faq.com
- From: Mark McIntyre
- A question regarding Q20.1 from c-faq.com
- Prev by Date: Re: Positive random number
- Next by Date: Re: function prototype vs function declaration
- 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
|