Hacker News new | past | comments | ask | show | jobs | submit login

The mental precedence list I have is:

* Name operators (e.g., a::b, a.b, a->b)

* a[b], a(b) expressions

* Unary suffix operators (C doesn't have these, but Rust's ? operator applies)

* Unary prefix operators

* Arithmetic operators, following normal mathematical precedence rules (i.e., a + b / c is a + (b / c), not (a + b) / c). Note that I don't have any mental model of how <<, &, |, ^ compare to each other or the normal {,/,%}; {+,-} rank.

Comparison operators

* Short-circuit operators (&&, ||)

* Ternary operator (?:)--and this one is right-associative.

* Assignment operators

This list I think is fairly objective, although C and some of its children "erroneously" place bitwise {&,|,^} below comparison operators instead of above them. The difference between suffix and prefix unary operators is somewhat debatable, but it actually does make sense if you think of array access and function call expressions as unary suffix operators instead of binary operators.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: