Precedence
Precedence rules in C3 differs from C/C++. Here are all precedence levels in C3, listed from highest (1) to lowest (11):
()
,[]
,.
,!!
postfix!
,++
and--
@
, prefix-
,~
, prefix*
,&
, prefix++
and--
- infix
*
,/
,%
<<
,>>
^
,|
, infix&
+
, infix-
,+++
==
,!=
,>=
,<=
,>
,<
&&
,&&&
||
,|||
- ternary
?:
??
=
,*=
,/=
,%=
,+=
,-=
,<<=
,>>=
,&=
,^=
,|=
The main difference is that bitwise operations and shift has higher precedence than addition/subtraction and multiplication/division in C3. Bitwise operations also have higher precedence than the relational operators. Also, there is no difference in precedence between && || or between the bitwise operators.
Examples:
The change in precedence of the bitwise operators corrects a long standing issue in the C specification. The change in precedence for shift operations goes towards making the precedence less surprising.
Conflating the precedence of relational and equality operations, and all bitwise operations was motivated by simplification: few remember the exact internal differences in precedence between bitwise operators. Parenthesis are required for those conflated levels of precedence.
Left-to-right offers a very simple model to think about the internal order of operations, and encourages use of explicit ordering, as best practice in C is to use parentheses anyway.