<p>With the exception of documentation code, no line of any code or test file shall exceed 132 characters. If a line break is required, then it shall be after the first function parenthesis:</p>
<code-block>
// CORRECT - location of line break after first function parenthesis if line length is greater than 132
<p>String constants can be declared using the <code>STRING_STATIC()</code> macro for local strings and <code>STRING_EXTERN()</code> for strings that will be extern'd for use in other modules.</p>
<p>Extern'd strings should be declared in the header file as:</p>
<code-blocktype="c">
#define SAMPLE_VALUE "STRING"
STRING_DECLARE(SAMPLE_VALUE_STR);
</code-block>
<p>And in the C file as:</p>
<code-blocktype="c">
STRING_EXTERN(SAMPLE_VALUE_STR, SAMPLE_VALUE);
</code-block>
<p>Static strings declared in the C file are not required to have a <code>#define</code> if the <code>#define</code> version is not used. Extern'd strings must always have the <code>#define</code> in the header file.</p>
<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>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>
<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>Hints are to be formatted with capitalized <id>HINT:</id> followed by a space and a sentence. The sentence shall only begin with a capital letter if the first word is an acronym (e.g. TLS) or a proper name (e.g. PostgreSQL). The sentence must end with a period, question mark or exclamation point as appropriate.</p>
<p>Warning and errors shall be lowercase with the exceptions for proper names and acronyms and end without punctuation.</p>
<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>
<p>Variadic functions can take a variable number of parameters. While the <code>printf()</code> pattern is variadic, it is not very flexible in terms of optional parameters given in any order.</p>
<p>This project implements variadic functions using macros (which are exempt from the normal macro rule of being all caps). A typical variadic function definition:</p>
<p>If the majority of functions in a module or object are variadic it is best to provide macros for all functions even if they do not have variable parameters. Do not use the base function when variadic macros exist.</p>
<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>