AND 运算符的求值顺序是否保证从左到右?

Is the order of evaluation of AND operator from left to right guaranted?

我正在学习 K&R“The C Programming Language”第 2 版书,在第 29 页的第 1.9 章字符数组中有一个示例程序,用于在读取一组行后打印出最长的行。程序中提供了一个示例 getline() 函数,该函数中有一个 for 循环,用于读取字符并检查有效性,如果有效则将其添加到字符数组中。 for 循环给出为

    for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
        s[i] = c;

我的问题是:什么保证 (c = getchar()) != EOFc != '\n' 之前评估?

根据我之前对 C 的了解,结合性顺序与求值顺序不同,并且 C 标准没有指定求值顺序。如果是这样,如果 c != '\n'(c = getchar()) != EOF 之前求值会发生什么?它应该用前一个字符而不是当前读取的字符来检查换行符,因为 getchar() 操作是在检查换行符之后完成的,对吗?

快速搜索 google 发现这种代码很常见,所以我怀疑如果我自己尝试一下它会成功。该书还声称所有示例程序都是工作程序。

什么保证 (c = getchar()) != EOFc != '\n' 之前的评估?

根据 C 标准(6.5.13 逻辑与运算符)

4 Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; if the second operand is evaluated, there is a sequence point between the evaluations of the first and second operands. If the first operand compares equal to 0, the second operand is not evaluated.