getc和“large”字节 [英] getc and "large" bytes

查看:51
本文介绍了getc和“large”字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设int的所有值都在unsigned char的范围内,如果getc返回EOF,那么

会发生什么?

EOF是否可能是值的字节读取?

这是否意味着针对最大可移植性的代码需要为feof()和ferror()检查



(例如,如果当
getc()返回EOF时feof()和ferror()都为流返回0,请考虑EOF读取有效字节。

对我来说,似乎是这种情况,但也许标准说这对于
是不正确的。


一如既往,所有回复都表示赞赏。

解决方案

vi******@gmail.com 写道:


假设int的所有值都在unsigned char范围内,那么如果getc返回EOF,那么

会发生什么?



您的假设是假的。

-

Ben Pfaff
http://benpfaff.org


5月23日,6日:35 pm,Ben Pfaff< b ... @ cs.stanford.eduwrote:


vipps ... @ gmail.com写道:
< blockquote class =post_quotes>
假设int的所有值都在unsigned char的范围内,那么如果getc返回EOF,那么

会发生什么?



你的假设是假的。



请详细说明吗?


vi ****** @ gmail.com 说:


5月23日下午6:35,Ben Pfaff < b ... @ cs.stanford.eduwrote:


> vipps ... @ gmail.com写道:


假设int的所有值都在unsigned char的范围内,那么如果getc返回EOF,那么

会发生什么?


你的假设是假的。



请详细说明一下?



int类型必须能够表示INT_MIN到-1范围内的值,

这些值都不在以下范围内: unsigned char(缺少

符号位,不能代表负值)。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


Assuming all the values of int are in the range of unsigned char, what
happends if getc returns EOF?
Is it possible that EOF was the value of the byte read?
Does that mean that code aiming for maximum portability needs to check
for both feof() and ferror()?
(for example, if both feof() and ferror() return 0 for the stream when
getc() returned EOF, consider EOF a valid byte read)
To me, that seems to be the case, but maybe the standard says this to
be incorrect.

As always, all replies appreciated.

解决方案

vi******@gmail.com writes:

Assuming all the values of int are in the range of unsigned char, what
happends if getc returns EOF?

Your assumption is false.
--
Ben Pfaff
http://benpfaff.org


On May 23, 6:35 pm, Ben Pfaff <b...@cs.stanford.eduwrote:

vipps...@gmail.com writes:

Assuming all the values of int are in the range of unsigned char, what
happends if getc returns EOF?


Your assumption is false.

Would you please elaborate?


vi******@gmail.com said:

On May 23, 6:35 pm, Ben Pfaff <b...@cs.stanford.eduwrote:

>vipps...@gmail.com writes:

Assuming all the values of int are in the range of unsigned char, what
happends if getc returns EOF?


Your assumption is false.

Would you please elaborate?

The int type must be able to represent values in the range INT_MIN to -1,
none of which values are in the range of unsigned char (which, lacking a
sign bit, cannot represent negative values).

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于getc和“large”字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆