Coding Style Guidelines

EPICS v4 Working Group, First Working Draft, 26-Oct-2011

This version:
Latest version:
Matej Sekoranja, Cosylab


This document defines EPICS v4 coding guidelines for C++

Status of this Document

This is the 26 October 2011 version of the coding style guidelines.

The present code does not completely follow guidelines described in this document.

The terms MUST, MUST NOT, SHOULD, SHOULD NOT, REQUIRED, and MAY when highlighted (through style sheets, and in uppercase in the source) are used in accordance with RFC 2119 [RFC2119]. The term NOT REQUIRED (not defined in RFC 2119) indicates exemption.

Table of Contents

  1. General rules
  3. Identifiers
  4. Code blocks
  5. Operators
  6. Other coding rules

General rules


Both C and C++ style comments are allowed.

// Compute the factorial.
int factorial = 1;
for (int i = 2; i != 11; i++)
    factorial *= i;

// Present the result to the user.
cout << "Factorial of 10 is " << factorial << "." << endl;


Identifiers follow Java naming convention using mixed case, e.g. bufferSize.

Identifiers should be meaningful rather than arbitrary. The only exception are control variables of short cycles where short names like i, iter etc. can be used.

int sum = 0;
for (int i = 0; i != 100; i++)
     sum += i;

The type of the variable should not be explicitly marked in the identifier. I.e. no hungarian notation.

Code blocks

For functions, structures, classes, enums and namespaces both opening bracket and closing bracket are placed on separate lines:

void fx()
    // Code goes here.

With for, while, if and else blocks opening bracket is on the same line as the control statement:

if (sum > 1000) {
    // Code goes here.

Even if for, while, if or else block contains only a single statement, the statement should be placed on a separate line:

if (end)

If the indenting of the controlled block incidentally collides with the control statement that's broken into two lines, second line of the control statement should be indented by 6 spaces rather than 4 to prevent confusion:

if (veryLongVariableName == 10000 &&
      anotherHorrendousVariableName == 1000000 &&
      ludicrouslyLongVariableName == 1000000000)


Unary operators are not separated from the expression in any way:


Binary operators should be separated from adjacent expression by spaces:

z = x + y;

Method and function calls are not separated from the expression by space(s):


Other coding rules