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

« Previous Version 2 Next »


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


The ForgeRock C coding style


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


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;

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

 * Document the purpose of the function.
 * Document the returned value for any non void function.





  • No labels