TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - C Coding Standard
Search

Guideline:  7.16#2Checked automatically with code checker

Synopsis:Use parentheses to improve readability of the conditional operator.
Language:C
Severity Level:6
Category:EXPRESSIONS


Description:

Parenthesizing the operands of the conditional operator can help readability. Hence,

Example:

len = ac_DataLength <= 3 ? ac_DataLength - 1 : ac_DataLength + 1;

should become

Example:

len = (ac_DataLength <= 3) ? (ac_DataLength - 1) : (ac_DataLength + 1);

If the operands are atomic expressions no parentheses are needed. For instance the following is allowed.

Example:

len = (ac_DataLength <= 3) ? ac_DataLength : 3;