Update to coding standard document and to a README file.

This commit is contained in:
Gregory Nutt
2017-06-11 10:01:14 -06:00
parent b7ca90a721
commit 40f60d6da5
2 changed files with 54 additions and 9 deletions
+45 -5
View File
@@ -12,7 +12,7 @@
<h1><big><font color="#3c34ec">
<i>NuttX C Coding Standard</i>
</font></big></h1>
<p>Last Updated: June 9, 2017</p>
<p>Last Updated: June 11, 2017</p>
</td>
</tr>
</table>
@@ -2150,12 +2150,24 @@ x++;
</td></tr>
</table></center>
<p>
<b>Forbidden Multicharacter Forms</b>.
Many operators are expressed as a character in combination with <code>=</code> such as <code>+=</code>, <code>>=</code>, <code>>>=</code>, etc.
Some compilers will accept the <code>=</code> at the beginning or the end of the sequence.
This standard, however, requires that the <code>=</code> always appear last in order to avoid amiguities that may arise if the <code>=</code> were to appear first. For example, <code>a =++ b;</code> could also be interpreted as <code>a =+ +b;</code> or <code>a = ++b</code> all of which are very different.
</p>
<p>
<h2>4.4 <a name="ifthenelse"></a><code>if then else</code> Statement</h2>
<p><b>Coding Standard:</b></p>
<ul>
<li>
<b><code>if</code> separated from <code>&lt;condition&gt;</code></b>.
The <code>if</code> keyword and the <code>&lt;condition&gt;</code> must appear on the same line.
The <code>if</code> keyword and the <code>&lt;condition&gt;</code> must be separated by a single space.
</li>
</li>
<b>Keywords on separate lines</b>.
<code>if &lt;condition&gt;</code> and <code>else</code> must lie on separate lines with nothing else present on the line.
</li>
@@ -2185,7 +2197,7 @@ x++;
Use of braces must follow all other standard rules for <a href="#braces">braces and spacing</a>.
</li>
<li>
<b>Exception where there is no blank line</b>.
<b>Exception</b>.
That blank line must also be omitted for certain cases where the <code>if &lt;condition&gt;</code>-<code>else</code> statement is nested within another compound statement; there should be no blank lines between consecutive right braces as discussed in the standard rules for use of <a href="#braces">braces</a>.
</li>
</ul>
@@ -2280,6 +2292,11 @@ x++;
<p><b>Coding Standard:</b></p>
<ul>
<li>
<b><code>switch</code> separated from <code>&lt;value&gt;</code></b>.
The <code>switch</code> keyword and the switch <code>&lt;value&gt;</code> must appear on the same line.
The <code>if</code> keyword and the <code>&lt;value&gt;</code> must be separated by a single space.
</li>
<li>
<b>Falling through</b>.
Falling through a case statement into the next case statement is be permitted as long as a comment is included.
@@ -2298,6 +2315,14 @@ x++;
<code>break</code> statements are normally indented by two spaces.
When used conditionally with case logic, the placement of the break statement follows normal indentation rules.
</li>
<li>
<b>Followed by a single blank line</b>.
The final right brace that closes the <code>switch &lt;value&gt;</code> statement must be followed by a single blank line.
</li>
<li>
<b>Exception</b>.
That blank line must be omitted for certain cases where the <code>switch &lt;value&gt;</code> statement is nested within another compound statement; there should be no blank lines between consecutive right braces as discussed in the standard rules for use of <a href="#braces">braces</a>.
</li>
</ul>
<p>
<b>Other Applicable Coding Standards</b>.
@@ -2333,6 +2358,11 @@ x++;
<h2>4.6 <a name="while"><code>while</code> Statement</a></h2>
<p><b>Coding Standard:</b></p>
<ul>
<li>
<b><code>while</code> separated from <code>&lt;condition&gt;</code></b>.
The <code>while</code> keyword and the <code>&lt;condition&gt;</code> must appear on the same line.
The <code>while</code> keyword and the <code>&lt;condition&gt;</code> must be separated by a single space.
</li>
<li>
<b>Keywords on separate lines</b>.
<code>while &lt;condition&gt;</code> must lie on a separate line with nothing else present on the line.
@@ -2356,7 +2386,11 @@ x++;
</li>
<li>
<b>Followed by a single blank line</b>.
The final right brace must be followed by a blank line.
The final right brace that closes the <code>while &lt;condition&gt;</code> statment must be followed by a single blank line.
</li>
<li>
<b>Exception</b>.
That blank line must be omitted for certain cases where the <code>while &lt;condition&gt;</code> statement is nested within another compound statement; there should be no blank lines between consecutive right braces as discussed in the standard rules for use of <a href="#braces">braces</a>.
</li>
</ul>
<p>
@@ -2404,15 +2438,20 @@ x++;
</li>
<li>
<b>Statements enclosed in braces</b>
Statement(s) following the <code>do</code> must always be enclosed in braces, even if only a single statement follows.
Statement(s) following the <code>do</code> must always be enclosed in braces, even if only a single statement (or no statement) follows.
</li>
<li>
<b>Braces and indentation</b>.
The placement of braces and statements must follow the standard rules for braces and indentation.
</li>
<li>
<b><code>while</code> separated from <code>&lt;condition&gt;</code></b>.
The <code>while</code> keyword and the <code>&lt;condition&gt;</code> must appear on the same line.
The <code>while</code> keyword and the <code>&lt;condition&gt;</code> must be separated by a single space.
</li>
<li>
<b>Followed by a single blank line</b>.
The final right brace must be followed by a blank line.
The concluding <code>while &lt;condition&gt;</code> must be followed by a single blank line.
</li>
</ul>
<p>
@@ -2447,6 +2486,7 @@ x++;
ptr++;
}
while (*ptr != '\0');
</ul></pre></font>
</td></tr>
</table></center>