Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在glibc 参考中,我们找到了这样的词:
...草率的代码,例如 { int c; ... while ((c = getc (fp)) < 0) ... } 必须重写...
...草率的代码,例如
{ int c; ... while ((c = getc (fp)) < 0) ... }
必须重写...
为什么在 glibc 参考中测试 int 的符号被称为“草率代码”?
这与WEOF 宏的使用有关。正如参考文献中已经提到的,(强调我的)
WEOF
WEOF不必是EOF与EOF 它相同的值,也不必是负值。[...]
EOF
因此,检查< 0可能是一个错误的决定,严格来说,应该对照WEOF自身的返回值进行检查。
< 0