本文介绍了getc和“large”字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 假设int的所有值都在unsigned char的范围内,如果getc返回EOF,那么 会发生什么? EOF是否可能是值的字节读取? 这是否意味着针对最大可移植性的代码需要为feof()和ferror()检查 ? (例如,如果当 getc()返回EOF时feof()和ferror()都为流返回0,请考虑EOF读取有效字节。 对我来说,似乎是这种情况,但也许标准说这对于是不正确的。 一如既往,所有回复都表示赞赏。 解决方案 您的假设是假的。 - Ben Pfaff http://benpfaff.org 你的假设是假的。 请详细说明吗? 你的假设是假的。 请详细说明一下? 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, whathappends 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 checkfor both feof() and ferror()?(for example, if both feof() and ferror() return 0 for the stream whengetc() returned EOF, consider EOF a valid byte read)To me, that seems to be the case, but maybe the standard says this tobe incorrect. As always, all replies appreciated. 解决方案 Your assumption is false.--Ben Pfaff http://benpfaff.org Your assumption is false.Would you please elaborate? 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 asign 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”字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 11:51