RTEMS includes a mixture of code which was developed specifically for RTEMS and code from actively maintained FOSS projects. This document addresses coding style issues within the RTEMS Project code base.

Unfortunately, RTEMS has never had a formal written set of coding conventions which have been reviewed and blessed by an ISO9000 committee of non-coders. However, the style of the code in RTEMS is generally very consistent in the core areas of RTEMS. This page attempts to capture some of the generally accepted practices.

Historically, the RTEMS project has not outright rejected any submission of general utility. We have worked with the authors to ensure that the code conforms to the standards. In many cases, the source code has been merged into the source base under the good faith assumption that concerns will be addressed. Sometimes that good faith was justified and in other cases, it was not.

As an exception, code the is merged from another source such as FreeBSD or another open source project into the RTEMS source tree will NOT be reformatted!!! This is critical as it makes it difficult to merge future updates and bug fixes.

1. Source from Other Projects

This code should remain as unmodified as possible. Any modifications made should adhere to the originating project’s style conventions. All changes should be submitted upstream.

1.1. FreeBSD Originated Code

RTEMS leverages FreeBSD for USB and TCP/IP functionality. We have to modify this code to account for RTEMS differences and implement multiple FreeBSD kernel APIs in terms of RTEMS. These will all follow the FreeBSD style.

XXX URL

2. RTEMS Project Owned Code

2.1. File Rules

/*
 *  COPYRIGHT (c) 2010-2012.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

2.2. Coding Rules

2.3. Source Code Formatting Rules

An example code method:

bool test_method(
  int arg1,
  int arg2
)
{
  if ( arg1 > arg 2 )
    return true;
  return false;
}

The above raises questions:

2.4. Performance Issues

Although style is important, RTEMS is a real-time operating system and, consequently, any enhancements or modifications should also have certain execution characteristics. The following is a list of guidelines which RTEMS adheres to in order to improve the performance and stability of the services it provides.

3. Formatting Tool Assistance

The RTEMS Project has identified two tools with potential for aiding in style adjustments.

Tool Project Site

astyle

http://astyle.sourceforge.net/

indent

XXX

This is based on a review of the manual and untested:

indent astyle

two space indent

TBD

TBD

brace style

TBD

TBD

padding around operators

TBD

--pad-oper

padding around parentheses

TBD

--pad-paren-in

space after if, while, for

TBD

--pad-header

align pointer with name

TBD

--align-pointer=name

UNIX CR/LF

TBD

--lineend=linux

3.1. indent Arguments

Eric Valette did some research and came up with a set of arguments for version 2.2.7 of the 'indent' program which seem to match the RTEMS style. So if you need help, try this and see how it does:

indent -br -ce -i2 -nut FILE.c

TBD: This desperately needs updating and augmenting

3.2. astyle Arguments

XXX

4. Editor Settings which Aid

4.1. gvim

If you are a vim user then the following additions to your .vimrc will assist in the indentation:

:set tabstop=2
:set shiftwidth=2
:set expandtab

4.2. emacs

XXX

4.3. Eclipse

XXX