Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Overview

This document covers coding guidelines to use when writing C code.  It is very much a WORK IN PROGRESS.

Copyright notices

All new source files must begin with the same copyright notice as recommended in the Coding Style and Guidelines

When writing particularly dense code, it is desirable to separate functions with some manner of visual separator.  The following is recommended:

/*********************************************************************************************************************
 *
 * Some form of documentation here.
 *
 *********************************************************************************************************************/

 

The ForgeRock C coding style

Summary

The ForgeRock C code style rules are based on the Java conventions with some deviations, the key points being:

  • source files MUST contain a valid copyright notice
  • source files MUST NOT contain tab characters
  • source files MUST NOT contain lines longer than 120 characters
  • source files MUST NOT contain lines with trailing white-space
  • code MUST be formatted using 4 character indents
  • curly braces MUST be on the same line as their associated statement
  • curly braces MUST ALWAYS be used with if, while, for and do/while
  • checking against NULL should ALWAYS be explicit rather than implied
  • never declare more than one pointer at a time
  • when declaring pointers, the * should be moved towards the type rather than the variable

Details

Consider the following example for the last few points listed above:

unsigned int *index = ..., entry_index = 0;
if (index) *index = entry_index;

should be written as:

unsigned int*  index = ...;
unsigned int   entry_index = 0;

if (index != NULL) {
    *index = entry_index;
}
  • No labels