:当下面的代码编译它进入一个无限循环比较无符号的字符和EOF
GCC编译器还提供了有关编译
abc.c:13:warning: comparison is always true due to limited range of data type
代码警告运行正常时unsigned char
是如预期的那样由char
或int
取代,即它终止。
但代码也运行良好unsigned int
以及。 因为我已经阅读EOF
被定义为-1
stdio.h
那么为什么此代码无效的无符号字符,但运行良好的无符号整型。
基本相同[龟etc不识别EOF](http://stackoverflow.com/questions/3977223/fgetc-does-not-identify-eof)。我认为我们每周至少有一次这类问题。 – 2011-12-21 08:28:11
另请参见http://c-faq.com/stdio/getcharc.html – 2011-12-21 08:30:31
[为什么必须将用于保存getchar的返回值的变量声明为int?](http://stackoverflow.com/questions/18013167/why-must-the-variable-used-to-hold-getchars-return-value-be-declared-as-int) – 2017-05-15 12:15:51