|
Page date Sat May 21 08:49:59 2011 . | Improve this page |
This document describes the recommended approaches for the format and structure of C++ source code files.
The guide is aimed to developers creating and editing C++ source code files.
This guide assumes the use of Eclipse CDT environment.
For consistency, it is strongly recommended to always use the Eclipse CDT formatter
The general formatting style of µOS++ source code is the default Eclipse CDT GNU style.
Source code lines should never exceed 79 columns.
The following binary operators are written with no space around them:
The unary operators are written with no spaces between them and their operands:
The binary operators are preceded and followed by one (1) space, as is the ternary operator:
The following keywords are followed by one (1) space:
In case of compound expressions, parenthesising should be used whenever the precedence is not “obvious”. In general, over parenthesising is recommended to remove any doubt and guessing.
All indentations must be exactly two (2) spaces to indicate scope.
Paired open and close parenthesis must have the same position:
class Parser
{
public:
Parser();
...
protected:
unsigned char* m_pLine;
...
};
The statement following any of the keywords (if, else, while, for, switch, case, do) must be compound, that is, use of braces is obligatory, even if the actual statement is singular.
if (condition)
{
i = 1;
}
else
{
i = 100;
}
Use C++ comments, one space separator and continue up to column 79. If text is used, it comes after 5 dashes, and is delimited by spaces.
// ----------------------------------------------------------------------------
// ----- Static data ----------------------------------------------------------
// ----- Constructors ---------------------------------------------------------