c语言中的EOF的详细情况

那是因为你把EOF( 0xffffffff ) 强制转换成 unsigned char 之后,就变成了 0xff 的一个unsigned类型,后面再和EOF比较的时候,EOF的类型是int,于是就两者都被转换成了unsigned int,那么就相当于比较0x000000ff != 0xffffffff这个永远都是true的。你可以做个实验unsigned char c = EOF;printf("%x, %x, %x\", c, (unsigned int) c, EOF);printf("%d\", c == EOF);-----补充引用-----引用getchar文档里的一句RETURN VALUES If successful, these routines return the next requested object from the stream. Character values are returned as an unsigned char converted to an int. If the stream is at end-of-file or a read error occurs, the routines return EOF. The routines feof(3) and ferror(3) must be used to distinguish between end-of-file and error. If an error occurs, the global variable errno is set to indicate the error. The end-of-file condi- tion is remembered, even on a terminal, and all subsequent attempts to read will return EOF until the condition is cleared with clearerr(3).其中The end-of-file condition is remembered, even on a terminal, and all subsequent attempts to read will return EOF until the condition is cleared with clearerr(3).
■网友
看来我确实层次不够,茴香豆的茴字我就知道一种写法,,,某些人嘛,还是屏蔽了算了。=========对于翻译,我认为还不至于坑爹。对于@薛非质疑书写的不对,对不起,我还只是个大三学生,层次不够,,无法和您探讨CSAPP这本书的内容究竟正确与否。===========================针对薛非大人的质疑,原版的CSAPP虽然我没有全看,但我翻看了一下,我认为翻译没问题。不知他为何质疑翻译“坑爹”?针对我说的第一条:是 无符号变量 ch要经过 零扩展 为 四字节无符号数。原书为:To convert an unsigned number to a larger data type, we can simply add leading zeros to the representation; this operation is known as zero extension.c语言中的EOF的详细情况

另外,位扩展还有另外一种 符号扩展的。针对我提的第二条:原文:When an operation is performed where one operand is signed and the other is unsigned, C implicitly casts the signed argument to unsigned and performs the operations assuming the numbers are nonnegative.c语言中的EOF的详细情况

再有,我说位扩展和有符号转换到无符号,这二者行为是有顺序的,那个例子原文里说的很清楚。c语言中的EOF的详细情况

the code isshort sx=-12345;unsigned uy=sx ;printf("uy =%u:\\t",uy);show_bytes((byte_pointer) \u0026amp;uy,sizeof(unsigned));and will output:uy=4294954951: ff ff cf c7c语言中的EOF的详细情况

Indeed this convention is required by the C standards.我水平不高,还没发现这儿有什么坑爹之处,尊敬的薛神==------------------------------------------------------------------------------手机上传的照片 画面就是不能忍噢……==。=======================手机上 码字,,, 我就说说你那个 while条件表达式吧,,,表达式里会发生两件事儿,是 无符号变量 ch要经过 零扩展 为 四字节无符号数。当表达式里同时出现 有符号数和无符号数时,有符号数会被 隐式转换成 无符号数。(c标准里就这么规定了)-----------------------------ps:题主运气好::\u0026gt;_\u0026lt;:: CSAPP这本书刚好在我手边。。。。针对我说的第一点,在该书 p49


推荐阅读