问题描述
h = b = out;
/* h is the number of code points that have been handled,b is the */
/* number of basic code points,and out is the number of ASCII code */
/* points that have been output. */
我无法弄清楚这行是否只是将h
和b
都设置为out
的怪异方式,还是设置{{1}的布尔表达式}等于h
(0?),如果true
已经等于b
。
解决方法
将h和b设置为out。
布尔值将为h ? b : out;
,表示如果h为真,则不存在-因此它没有为h设置
它不能是布尔值,因为它将使用==
而不是=
。
所以是的,基于b=out
的值为out
的事实,这是设置两个变量的一种(奇怪的)方法。
=
在C中总是 赋值运算符,不能用于比较2个值。要获取“布尔”表达式,必须使用==
。表达式a = b
将b分配给a,并且返回分配的值,该值可以在另一个表达式中使用。因此h = b = out;
实际上将out
分配给b
和h
。它被解析为h = (b = out)
,因为在C中,=
运算符是left associative
,赋值还返回与存储在
lhs
中的值相同的值(因此可以使用诸如a = b = c
之类的表达式)。赋值运算符的value category为非左值(因此(a=b)=c
之类的表达式无效)。https://en.cppreference.com/w/c/language/operator_assignment
h = b = out; 在C语言中,这意味着将h和b都设置为等于out。 h =(b = out);意思是布尔表达式。