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 6 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

 

The ForgeRock C coding style

Summary

The ForgeRock C code style rules are based on the Java conventions:

  • source files MUST contain a valid copyright notice
  • source files MUST NOT contain tab characters - code MUST be formatted using 4 character indents
  • source files MUST NOT contain lines longer than 120 characters
  • curly braces MUST ALWAYS be used with if, while, for and do/while and appear on the SAME LINE as the associated keyword
  • 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
  • macros must ALWAYS be defined in UPPERCASE
  • always include system header files before local header files
  • try to leave at least one blank line between declarations and code within a function, unless the function is particularly short
  • document each and every function, giving its purpose, parameters and return value (for non void functions)

Details

Consider the following example for a few of the points listed above:

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

should be written as:

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

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

 

 

 

  • No labels