Documentation/NuttXCCodingStandard.html: Another small change discouraging the practice of enclosing the value argument of 'return' statements in parentheses.
This commit is contained in:
parent
bd248b52e4
commit
9be93c710a
@ -87,7 +87,7 @@
|
|||||||
<h1><big><font color="#3c34ec">
|
<h1><big><font color="#3c34ec">
|
||||||
<i>NuttX C Coding Standard</i>
|
<i>NuttX C Coding Standard</i>
|
||||||
</font></big></h1>
|
</font></big></h1>
|
||||||
<p>Last Updated: July 5, 2019</p>
|
<p>Last Updated: July 6, 2019</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -2092,7 +2092,14 @@ ptr = (FAR struct somestruct_s *)value;
|
|||||||
As a rule of thumb, the length of a function should be limited so that it would fit on a single page (if you were to print the source code).
|
As a rule of thumb, the length of a function should be limited so that it would fit on a single page (if you were to print the source code).
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<b>Space after the function body</b>
|
<b>Return Statement</b>.
|
||||||
|
The argument of the <code>return</code> statement should <i>not</i> be enclosed in parentheses.
|
||||||
|
A reasonable exception is the case where the returned value argument is a complex expression and where the parentheses improve the readability of the code.
|
||||||
|
Such complex expressions might be Boolean expressions or expressions containing conditions.
|
||||||
|
Simple arithmetic computations would not be considered <i>complex</i> expressions.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Space after the function body</b>.
|
||||||
A one (and only one) blank line must follow the closing right brace of the function body.
|
A one (and only one) blank line must follow the closing right brace of the function body.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -2121,7 +2128,7 @@ ptr = (FAR struct somestruct_s *)value;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return e / a;
|
return (e / a);
|
||||||
}
|
}
|
||||||
</ul></pre></font>
|
</ul></pre></font>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
@ -2129,28 +2136,28 @@ ptr = (FAR struct somestruct_s *)value;
|
|||||||
<p><font color="green"><b>Correct</b></p>
|
<p><font color="green"><b>Correct</b></p>
|
||||||
<ul><pre>
|
<ul><pre>
|
||||||
int myfunction(int a, int b)
|
int myfunction(int a, int b)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
int d;
|
int d;
|
||||||
int e;
|
int e;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
c = a
|
c = a
|
||||||
d = b;
|
d = b;
|
||||||
e = c + d;
|
e = c + d;
|
||||||
|
|
||||||
for (i = 0; i < a; i++)
|
for (i = 0; i < a; i++)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
for (j = 0; j < b; j++)
|
for (j = 0; j < b; j++)
|
||||||
{
|
{
|
||||||
e += j * d;
|
e += j * d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return e / a;
|
return e / a;
|
||||||
}
|
}
|
||||||
</ul></pre></font>
|
</ul></pre></font>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
</table></center>
|
</table></center>
|
||||||
|
Loading…
Reference in New Issue
Block a user