You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changing the order of precedence of the C operators is problematic:
it causes more confusion for little benefit.
it is inconsistent with the C syntax (breaks the philosophy Should be easy to learn for C programmers)
it is inconsistent with other languages that inherit the C operators: c++, java, javascript, csharp, kotlin... that have huge momentum, making C2 quite unfriendly to learn and port code to.
it is unnecessary to fix the problem.
I propose you keep the same order of precedence, but require explicit parentheses for subexpressions when mixed with other operators whose precedence is deemed counter-intuitive or at least confusing. This is what clang and gcc do with strict warning levels and does not break compatibility: code that compiles in C2 would parse to the same AST in the other languages.
a + b >> c + d would require parentheses to lift the confusion between a + (b >> c) + d and (a + b) >> (c + d).
Same for a & b == c which should always be written (a & b) == c
a || b && c would become a || (b && c) or (a || b) && c depending on the programmer's intent, which is non obvious.
But a & b & c, a && b && c... would be accepted as unambiguous.
I think the is a better approach for the philosophy Should help to avoid common mistakes.
The text was updated successfully, but these errors were encountered:
Again, this was discussed a Lot. I think the C system is a big cause for bugs. Many programmers are unsure and just add some parenthesis to make sure. This is fine I think and also makes the code easier to read without having to memorize the whole precedence table.
Maybe we could add a warning in the compiler when this happens?
Again, this was discussed a Lot. I think the C system is a big cause for bugs. Many programmers are unsure and just add some parenthesis to make sure. This is fine I think and also makes the code easier to read without having to memorize the whole precedence table.
Yes, and mandating these parentheses seems to me a better fix than changing the precedence rules.
Changing the order of precedence of the C operators is problematic:
I propose you keep the same order of precedence, but require explicit parentheses for subexpressions when mixed with other operators whose precedence is deemed counter-intuitive or at least confusing. This is what clang and gcc do with strict warning levels and does not break compatibility: code that compiles in C2 would parse to the same AST in the other languages.
a + b >> c + d
would require parentheses to lift the confusion betweena + (b >> c) + d
and(a + b) >> (c + d)
.Same for
a & b == c
which should always be written(a & b) == c
a || b && c
would becomea || (b && c)
or(a || b) && c
depending on the programmer's intent, which is non obvious.But
a & b & c
,a && b && c
... would be accepted as unambiguous.I think the is a better approach for the philosophy Should help to avoid common mistakes.
The text was updated successfully, but these errors were encountered: