sysprog21 / shecc

A self-hosting and educational C optimizing compiler
BSD 2-Clause "Simplified" License
1.11k stars 118 forks source link

Implement short-circuit evaluation of `&&` operator #137

Closed vacantron closed 3 months ago

vacantron commented 3 months ago

According to the C99 standard (6.5.13):

The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it yields 0. The result has type int. Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares equal to 0, the second operand is not evaluated.

The latter operand should not be evaluated if the former is the expression of 0.