Moderators: misra-c, david ward
- Posts: 20
- Joined: Fri Jul 27, 2007 3:25 pm
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?
Code: Select all
x = a + b; /* acceptable */
x = (a + b); /* () not required */
- Posts: 572
- Joined: Thu Jan 05, 2006 1:11 pm
There is no situation in which too many parentheses would violate this rule. Both forms:
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.
Posted by and on behalf of
the MISRA C Working Group