📄 x-coding3.html
字号:
<p class="listspace"><ul class="Bullet" type="disc"><li><a name="84532"> </a>Compose multi-line comments in declarations and at the end of code statements with one or more one-line comments, opened and closed on the same line. For example:</li></ul></p><dl class="margin"><dd><pre class="Code2"><b><a name="84533">int foo ( int a, /* this is the correct format for a */ /* multiline comment in a declaration */ BOOL b /* standard comment at the end of a line */ )</a></b><dd> <b><a name="84534"> { day = night; /* when necessary, a comment about a line */ /* of code can be done this way */ }</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84537">I.3.5 C Naming Conventions</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84539"> </a>The following conventions define the standards for naming modules, routines, variables, constants, macros, types, and structure and union members. The purpose of these conventions is uniformity and readability of code.</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84540"> </a>When creating names, remember that the code is written only once, but read many times. Assign names that are meaningful and readable; avoid obscure abbreviations.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84542"> </a>Names of routines, variables, and structure and union members are composed of upper- and lowercase characters and no underbars. Capitalize each "word" except the first:</li></ul></p><dl class="margin"><dd><div class="Indent"><a name="84543"> </a><b class="symbol_lc">aVariableName</b></div><br></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84544"> </a>Names of defined types (defined with <b class="keyword">typedef</b>), and constants and macros (defined with <b class="keyword">#define</b>), are all uppercase with underbars separating the words in the name:</li></ul></p><dl class="margin"><dd><div class="Indent"><a name="84545"> </a><b class="symbol_UC">A_CONSTANT_VALUE</b> </div><br></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84546"> </a>Every module has a short prefix (two to five characters). The prefix is attached to the module name and all externally available routines, variables, constants, macros, and<b class="keyword"> typedefs</b>. (Names not available externally do not follow this convention.)<p class="table"><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84549"> </a><b class="symbol_lc">fooLib.c</b> </p></td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84551"> </a>module name</p></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84553"> </a><b class="symbol_lc">fooObjFind</b> </p></td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84555"> </a>subroutine name</p></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84557"> </a><b class="symbol_lc">fooCount</b> </p></td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84559"> </a>variable name</p></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84561"> </a><b class="symbol_UC">FOO_MAX_COUNT</b> </p></td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84563"> </a>constant</p></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84565"> </a><b class="symbol_UC">FOO_NODE</b> </p></td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84567"> </a>type </p></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84568"> </a>Names of routines follow the <i class="emphasis">module</i>-<i class="emphasis">noun</i>-<i class="emphasis">verb</i> rule. Start the routine name with the module prefix, followed by the noun or object that the routine manipulates. Conclude the name with the verb or action the routine performs:<p class="table"><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84571"> </a><b class="symbol_lc">fooObjFind</b> </p></td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84573"> </a>foo - object - find</p></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84575"> </a><b class="symbol_lc">sysNvRamGet</b> </p></td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84577"> </a>system - NVRAM - get</p></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84579"> </a><b class="symbol_lc">taskSwitchHookAdd </b></p></td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84581"> </a>task - switch hook - add</p></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84582"> </a>Every header file defines a preprocessor symbol that prevents the file from being included more than once. This symbol is formed from the header file name by prefixing <b class="symbol_UC">__INC</b> and removing the dot (<b class="operator">.</b>). For example, if the header file is called <b class="file">fooLib.h</b>, the <i class="emphasis">multiple inclusion guard symbol</i> is:</li></ul></p><dl class="margin"><dd><div class="Indent"><a name="84583"> </a><b class="symbol_lc">__INCfooLibh </b></div><br></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84584"> </a>Pointer variable names have the prefix <i class="term">p</i> for each level of indirection. For example:</li></ul></p><dl class="margin"><dd><pre class="Code2"><b><a name="84585">FOO_NODE * pFooNode; FOO_NODE ** ppFooNode; FOO_NODE *** pppFooNode;</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84587">I.3.6 C Style</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84589"> </a>The following conventions define additional standards of programming style:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84590"> </a><font face="Helvetica, sans-serif" size="-1" class="sans"><b class="hb">Comments:</b></font> Insufficiently commented code is unacceptable.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84591"> </a><font face="Helvetica, sans-serif" size="-1" class="sans"><b class="hb">Numeric Constants:</b></font> Use <b class="keyword">#define</b> to define meaningful names for constants. Do not use numeric constants in code or declarations (except for obvious uses of small constants like 0 and 1).</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84592"> </a><font face="Helvetica, sans-serif" size="-1" class="sans"><b class="hb">Boolean Tests:</b></font> Do not test non-booleans as you test a boolean. For example, where <b class="symbol_lc">x</b> is an integer:<p class="table"><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85098"> </a>CORRECT:</p></td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="85100">if (x == 0)</a></b></pre></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85102"> </a>INCORRECT:</p></td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="85104">if (! x)</a></b></pre></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></li></ul></p><dl class="margin"><dd><div class="Indent"><a name="84597"> </a>Similarly, do not test booleans as non-booleans. For example, where <b class="symbol_lc">libInstalled</b> is declared as <b class="symbol_UC">BOOL</b>:<p class="table"><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85111"> </a>CORRECT:</p></td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="85113">if (libInstalled)</a></b></pre></td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85115"> </a>INCORRECT:</p></td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="85117">if (libInstalled == TRUE)</a></b></pre></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></div><br></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84602"> </a><font face="Helvetica, sans-serif" size="-1" class="sans"><b class="hb">Private Interfaces:</b></font> Private interfaces are functions and data that are internal to an application or library and do not form part of the intended external user interface. Place private interfaces in a header file residing in a directory named <b class="file">private</b>. End the name of the header file with an uppercase <i class="term">P</i> (for <i class="term">private</i>). For example, the private function prototypes and data for the commonly used internal functions in the library <b class="library">blahLib</b> would be placed in the file <b class="file">private/private/blahLibP.h</b>. </li></ul></p><p class="listspace">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -