isspace()是否接受getchar()值? [英] Does isspace() accept getchar() values?
问题描述
isspace()
如果输入是可表示为unsigned char
或等于EOF
.
getchar()
从stdin读取下一个字符.
getchar()
reads the next character from stdin.
当getchar()!=EOF
时;所有getchar()
返回的值都可以表示为unsigned char
吗?
When getchar()!=EOF
; are all getchar()
returned values representable as unsigned char
?
uintmax_t count_space = 0;
for (int c; (c = getchar()) != EOF; )
if (isspace(c))
++count_space;
此代码是否可能导致未定义的行为?
May this code lead to the undefined behavior?
推荐答案
根据C11
§7.21.7.6/2 §7.21.7.6/2 The §7.21.7.5/2 §7.21.7.5/2 The §7.21.7.1/2 [ §7.21.7.1/2 [ 即 如果您认为它太明显了(还有什么其他意义"),请再考虑一下.例如,在相关情况中: If you think it is too obvious ("what else can it be"), think again. For example, in the related case: 如果 If §6.3.1.3/3 否则,将对新类型进行签名并且无法在其中表示值;结果是实现定义的,还是引发实现定义的信号. §6.3.1.3/3 Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised. 这篇关于isspace()是否接受getchar()值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!getchar
函数等效于getc
,其参数为stdin.
getchar
function is equivalent to getc
with the argument stdin.getc
功能等效于fgetc
... getc
function is equivalent to fgetc
...!=EOF
情况] ... fgetc
函数获取该字符作为转换为int
... 的unsigned char
[...]中的文字是我的. !=EOF
case] ...the fgetc
function obtains that character as an unsigned char
converted to an int
...text in [...] is mine.
isspace()
接受getchar()
值getchar()!=EOF
值都可以表示为unsigned char
isspace()
accepts getchar()
valuesgetchar()!=EOF
values are representable as unsigned char
isspace(CHAR_MIN)
可能是不确定的,即,将字符传递给字符分类功能! isspace(CHAR_MIN)
may be undefined i.e., it may be undefined behavior to pass a character to a character classification function! UCHAR_MAX > INT_MAX
结果可能是实现定义的:UCHAR_MAX > INT_MAX
the result may be implementation-defined: