TIL that you can't perform an assignment in the second branch of a ternary operator because ternary has higher precedence than assignment.

On a related note, I'm pretty happy with how my toy C compiler reports errors now—it almost looks like GCC and Clang, at least for these simple cases.

#PLdev #compilerdev

@lesley the assignment operator is so error-prone. To my understanding, the precedence of assignment is not straightforward.
×

TIL that you can't perform an assignment in the second branch of a ternary operator because ternary has higher precedence than assignment.

On a related note, I'm pretty happy with how my toy C compiler reports errors now—it almost looks like GCC and Clang, at least for these simple cases.

#PLdev #compilerdev

@lesley you can do it using parentheses though
@lesley oh, yeah, that makes sense because I used to use ternary sometimes to select the assigned. E. G. Cond? a:b = x would assign to either a or b depending on Cond.
@lesley the assignment operator is so error-prone. To my understanding, the precedence of assignment is not straightforward.
@lesley I mean, you can add parens. But the ternary operator is evil anyway 😅

@malwareminigun The ternary operator shouldn't exist, because ‘if’ should be an expression. In fact, statements were a mistake.

Yes this my hill and yes I will fight you for it

@lesley