<p><code>#define</code> constants should be all caps with <id>_</id> separators.</p>
<code-block>
#DEFINE MY_CONSTANT "STRING"
</code-block>
<p>The value should be aligned at column 69 whenever possible.</p>
<p>This type of constant should mostly be used for strings. Use enums whenever possible for integer constants.</p>
<p><b>Enum Constants</b></p>
<p>Enum elements follow the same case rules as variables. They are strongly typed so this shouldn't present any confusion.</p>
<code-block>
typedef enum
{
cipherModeEncrypt,
cipherModeDecrypt,
} CipherMode;
</code-block>
<p>Note the comma after the last element. This reduces diff churn when new elements are added.</p>
</section>
<sectionid="macros">
<title>Macros</title>
<p>Macro names should be upper-case with underscores between words. Macros (except simple constants) should be avoided whenever possible as they make code less clear and test coverage harder to measure.</p>
<p>Macros should follow the format:</p>
<code-block>
#define MACRO(paramName1, paramName2) \
<code>
</code-block>
<p>If the macro defines a block it should look like:</p>
<code-block>
#define MACRO_2(paramName1, paramName2) \
{ \
<code> \
}
</code-block>
<p>Continuation characters should be aligned at column 132 (unlike the examples above that have been shortened for display purposes).</p>
<p>To avoid conflicts, variables in a macro will be named <id>[macro name]_[var name]</id>, e.g. <id>TEST_RESULT_resultExpected</id>. Variables that need to be accessed in wrapped code should be provided accessor macros.</p>
</section>
<sectionid="begin-end">
<title>Begin / End</title>
<p>Use <id>Begin</id> / <id>End</id> for names rather than <id>Start</id> / <id>Finish</id>, etc.</p>
</section>
<sectionid="new-free">
<title>New / Free</title>
<p>Use <id>New</id> / <id>Free</id> for constructors and destructors rather than <id>Create</id> / <id>Destroy</id>, etc.</p>
</section>
</section>
<sectionid="formatting">
<title>Formatting</title>
<sectionid="braces">
<title>Braces</title>
<p>C allows braces to be excluded for a single statement. However, braces should be used when the control statement (if, while, etc.) spans more than one line or the statement to be executed spans more than one line.</p>
<p>No braces needed:</p>
<code-block>
if (condition)
return value;
</code-block>
<p>Braces needed:</p>
<code-block>
if (conditionThatUsesEntireLine1 &&
conditionThatUsesEntireLine2)
{
return value;
}
</code-block>
<code-block>
if (condition)
{
return
valueThatUsesEntireLine1 &&
valueThatUsesEntireLine2;
}
</code-block>
</section>
</section>
</section>
<sectionid="language-elements">
<title>Language Elements</title>
<sectionid="data-types">
<title>Data Types</title>
<p>Don't get exotic - use the simplest type that will work.
Use <id>int</id> or <id>unsigned int</id> for general cases. <id>int</id> will be at least 32 bits. When not using <id>int</id> use one of the types defined in <file>common/type.h</file>.</p>
</section>
<sectionid="macros">
<title>Macros</title>
<p>Don't use a macro when a function could be used instead. Macros make it hard to measure code coverage.</p>
</section>
<sectionid="objects">
<title>Objects</title>
<p>Object-oriented programming is used extensively. The object pointer is always referred to as <id>this</id>.</p>
</section>
</section>
<sectionid="testing">
<title>Testing</title>
<sectionid="uncoverable-uncovered">
<title>Uncoverable/Uncovered Code</title>
<sectionid="uncoverable">
<title>Uncoverable Code</title>
<p>The <id>uncoverable</id> keyword marks code that can never be covered. For instance, a function that never returns because it always throws a error. Uncoverable code should be rare to non-existent outside the common libraries and test code.</p>
<code-block>
} // {uncoverable - function throws error so never returns}
</code-block>
<p>Subsequent code that is uncoverable for the same reason is marked with <code>// {+uncoverable}</code>.</p>
</section>
<sectionid="uncovered">
<title>Uncovered Code</title>
<p>Marks code that is not tested for one reason or another. This should be kept to a minimum and an excuse given for each instance.</p>