【发布时间】:2015-10-10 00:44:55
【问题描述】:
所以一个 int 是四个字节,我只是不明白 C 是如何知道在这种情况下使它工作的
随机函数来说明我的意思
char strl[20];
int c, i=0;
puts("Enter a string up to 19 characters");
while((i<20) && (c=getChar())!="\n")
strl[i++]=c;
【问题讨论】:
-
C11 标准草案,
6.5.16.1 Simple assignment, Section 2 In simple assignment (=), the value of the right operand is converted to the type of the assignment expression and replaces the value stored in the object designated by the left operand.6.5.16 Assignment operators, Section 3 An assignment expression has the value of the left operand after the assignment[...]。 -
啊,复制粘贴第二个引用的错误句子:
[...]The type of an assignment expression is the type the left operand would have after lvalue conversion. -
我认为如果它在读取换行符之前到达 EOF 是未定义的,因为 EOF 不是有效的
char值。 -
@EOF 给定你的句柄,你能确认一下吗?
-
EOF 是一个宏,在 *NIX 世界中的值为 -1
标签: c char int undefined-behavior