Update Coding Standard Document.

This commit is contained in:
Gregory Nutt 2017-06-09 11:02:08 -06:00
parent 4504ca7c82
commit d1f69822d8

View File

@ -12,7 +12,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: May 6, 2017</p> <p>Last Updated: June 9, 2017</p>
</td> </td>
</tr> </tr>
</table> </table>
@ -736,12 +736,25 @@ void some_function(void)
<ul> <ul>
<li> <li>
<b>Always on Separate Lines</b>. <b>Always on Separate Lines</b>.
Braces always appear on a separate line containing nothing else other that white space. Braces always appear on a separate line containing nothing else other than white space.
</li> </li>
<li> <li>
<b>Never Comments on Braces</b>. <b>Never Comments on Braces</b>.
Do not put comments on the same line as braces. Do not put comments on the same line as braces.
</li> </li>
<li>
<b>Compound Statements</b>.
Within this document, an opening left brace followed by a sequence of statments, and ending with a closing right brace is refered to as a <i>compound statement</i>.
</li>
<li>
<b>Nested Compound Statements</b>.
In the case where there are nested compound statements that end with several consecutive right braces, each closing right brace must lie on a separate line and must be indented to match the corresponding opening brace.
</li>
<li>
<b>Final brace followed by a single blank line</b>.
The <i>final</i> right brace must be followed by a blank line as per standard rules.
In the case where there are nested several consecutive right braces, no blank lines should be inserted except for after the <i>final</i> right brace.
</li>
<li> <li>
<b>Special Indentation Rules</b>. <b>Special Indentation Rules</b>.
Special <a href="#indentation">indentation rules</a> apply to braces. Special <a href="#indentation">indentation rules</a> apply to braces.
@ -763,6 +776,19 @@ while (true)
... ...
} /* not valid */ } /* not valid */
} /* end forever */ } /* end forever */
if (a < b) {
if (a < 0) {
c = -a;
} else {
c = a;
}
} else {
if (b < 0) {
c = -b;
} else {
c = b;
}
}
</ul></pre></font> </ul></pre></font>
</td></tr> </td></tr>
<tr><td bgcolor="white"> <tr><td bgcolor="white">
@ -779,12 +805,36 @@ while (true)
... ...
} }
} }
if (a < b)
{
if (a < 0)
{
c = -a;
}
else
{
c = a;
}
}
else
{
if (b < 0)
{
c = -b;
}
else
{
c = b;
}
}
</ul></pre></font> </ul></pre></font>
</td></tr> </td></tr>
</table></center> </table></center>
<p> <p>
<b>Exceptions</b>. <b>Exception to Indentation Rule for Braces</b>.
The exception is braces that following structure, enumeration, union, and function declarations. The exception is braces that following structure, enumeration, union, and function declarations.
There is no additional indentation for those braces; There is no additional indentation for those braces;
those braces align with the beginning of the definition those braces align with the beginning of the definition
@ -854,6 +904,7 @@ int animals(int animal)
{ {
... ...
} }
</ul></pre></font> </ul></pre></font>
</td></tr> </td></tr>
</table></center> </table></center>
@ -2123,11 +2174,15 @@ x++;
</li> </li>
<li> <li>
<b>Braces and indentation</b>. <b>Braces and indentation</b>.
The placement of braces and statements must follow the standard rules for braces and indentation. The placement of braces and statements must follow the standard rules for <a href="#braces">braces and indentation</a>.
</li> </li>
<li> <li>
<b>Followed by a single blank line</b>. <b>Final brace followed by a single blank line</b>.
The final right brace must be followed by a blank line. The <i>final</i> right brace must be followed by a blank line.
This may be the final brace of the <code>if</code> compound statement.
Or it may be the the final brace of the <code>else</code> compound statement if present.
A blank line never follows the right brace closing the <code>if</code> compound statement if <code>else</code> is present.
Use of braces must follow all other standard rules for <a href="#braces">braces and spacing</a>.
</li> </li>
</ul> </ul>
<p> <p>