Bug with compiler or am I just doing something illegal

P

Peter Nilsson

raphfrk said:
Ahh, so the EOF return is in effect useless if you want 100% portable
code.

Yes, but no one wants to write 100% portable code. Most people are
happy with 99.9999%. Hell, Windoze programmers are happy with 5%. ;-)

AFAIK, no implementation writer has yet built a hosted implementation
where INT_MAX < UCHAR_MAX, intending it for practical use.

I know of one case where it was considered (with old Crays,) but it
was
rejected because the vast majority of code assumes that isn't the
case.
 
C

CBFalconer

pete said:
It makes more sense to me to check what fgetc returns,
and then to only check feof and ferror, if fgetc returned EOF.

Surprise - the fgetc function _does_ return EOF on any i/o error or
file EOF. If you care, you can distinguish between them with feof
and ferror.
 
K

Keith Thompson

CBFalconer said:
Surprise - the fgetc function _does_ return EOF on any i/o error or
file EOF. If you care, you can distinguish between them with feof
and ferror.

If you'll go back and read the context that you snipped, you'll find
that we were discussing a (likely nonexistent but theoretically
possible) system on which fgetc can *also* return EOF on reading a
valid character.

(For this to be possible, sizeof(int) must be 1, which implies
CHAR_BIT>=16.)
 
C

CBFalconer

Keith said:
If you'll go back and read the context that you snipped, you'll find
that we were discussing a (likely nonexistent but theoretically
possible) system on which fgetc can *also* return EOF on reading a
valid character.

Actually, I snipped nothing. The quote was (and is) the complete
message to which I replied, and it also contained no indication of
snipping. It's not worth fussing about, but as I see it fgetc can
always return EOF in place of a char. If sizeof(char) ==
sizeof(int) then some considerations are needed to restrict the
available chars, for example to those signified by positive ints.
 
R

Richard Tobin

If you'll go back and read the context that you snipped, you'll find
that we were discussing a (likely nonexistent but theoretically
possible) system on which fgetc can *also* return EOF on reading a
valid character.

I think Chuck may have misunderstood "if fgetc returned EOF" to mean
"if the fgetc() function were defined to return EOF" rather than "if
this call to fgetc() happens to return EOF". But I could be wrong.

-- Richard
 
W

Willem

Richard Tobin wrote:
) I think Chuck may have misunderstood "if fgetc returned EOF" to mean
) "if the fgetc() function were defined to return EOF" rather than "if
) this call to fgetc() happens to return EOF". But I could be wrong.

It would have been better worded as "when fgetc returns EOF", I think.
English has these subtle differences between 'if' and 'when', you see.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
K

Keith Thompson

CBFalconer said:
Actually, I snipped nothing. The quote was (and is) the complete
message to which I replied, and it also contained no indication of
snipping.

You're right. The snipping that lost the context (that we were
talking about exotic systems) took place several messages upthread.
I should have checked that myself before complaining.
It's not worth fussing about, but as I see it fgetc can
always return EOF in place of a char. If sizeof(char) ==
sizeof(int) then some considerations are needed to restrict the
available chars, for example to those signified by positive ints.

Not necessarily. Suppose sizeof(char)==sizeof(int), and both types
are 16 bits, signed, and two's-complement. Then there are 65536
possible byte values that can be read from a file. You can still read
and distinguish all possible byte values, as long as you check feof()
and ferror() in addition to the usual comparison against EOF -- as
long as the conversion from unsigned char to int is sufficiently well
behaved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top