Rule 12.1 - are extra parentheses not compliant?

6.12 Expressions

Moderators: misra-c, david ward

Locked
pkruk
Posts: 20
Joined: Fri Jul 27, 2007 3:25 pm

Rule 12.1 - are extra parentheses not compliant?

Post by pkruk » Tue May 13, 2008 3:36 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 */

misra-c
Posts: 572
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 12.1 - are extra parentheses not compliant?

Post by misra-c » Tue May 20, 2008 6:01 pm

There is no situation in which too many parentheses would violate this rule. Both forms:

Code: Select all

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.
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.12 Expressions”