C/C++ Programming Style Guidelines



->
", "
.
", "
()
" and "
[]
" operators. Leave no space between these
operators and their operands. When breaking operations across lines, put the operator
at the end of the broken line rather than at the start of the continuation line.

Use four spaces for each level of indentation. Avoid making lines longer than 80
characters. When breaking lines, use the natural logical breaks to determine where the
newline goes. Indent the continuation line to illustrate its logical relationship to the rest
of the code in the line. For functions, for example, this means aligning arguments with
the opening parenthesis of the argument list.

Example 4. Breaking statements across multiple lines
new_shape = affine_transform(coords, translation,
rotation);
if ( ( (new_shape.x > left_border) &&
(new_shape.x < right_border) ) &&
( (new_shape.y > bottom_border) &&
(new_shape.y < top_border) ) )
{
draw(new_shape);
}
Use a pure-block, fully bracketed style for blocks of code. This means put brackets
around all conditional code blocks, even one-line blocks, and put the opening bracket at
the end of the line with the opening statement. The exception to this rule is for
conditions that are broken across multiple lines. In this case put the open bracket on a
line by itself aligned with the start of the opening statement (as shown above).

Example 5. Fully bracketed, pure block style
if (value < max)
{
if (value != 0)
{
func(value);
}