MISRA Discussion Forums

Full Version: Rule 12.1 - are extra parentheses not compliant?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Quote:However, do not add too many parentheses so as to clutter the code and make it unreadable.
Does it means that the "not required" parentheses below are a violation of this rule? If not, is there a case where too many parentheses is a violation to this rule?
x = a + b; /* acceptable */
x = (a + b); /* () not required */
There is no situation in which too many parentheses would violate this rule. Both forms:

x = a + b;
x = (a + b);
are perfectly acceptable.

If parentheses are nested too deeply then you may hit a translation limit but if this happens the expression is probably too complicated anyway and should be split.

Rule 12.1 recognises that it would clutter code considerably if every expression were parenthesised. It leaves the matter of what constitutes "too much" clutter up to individual or organisational choice.