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

This style is mainly oriented around the desire to make C code more readable.  Unless otherwise stated, the Kernighan and Ritchie style reigns supreme.  Under no circumstances should the infinitely ugly GNU C style be used.  Ever.


The ForgeRock C code style rules are based on the Coding Style and Guidelines except that I think we can safely ignore the 120 column limit on line lengths - we have big screens.


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

int my_func(int *p,int c) {
	unsigned int *index = p + c - 1, entry_index=0;
	if (index) *index=entry_index;

should be written as:

 * The function my_func divides by the number you first thought of, which is useful when
 * parsing HTTP header information.
 * Parameters:
 *    int_base is a pointer to a block of memory containing a series of signed integers
 *    count is the number of signed integers in the block pointed to by "int_base"
 * Return:
 *    If successful, the function returns 1, if unsuccessful, the function returns 0
int my_func(int* int_base, int count) {
	unsigned int*  index = int_base + count - 1;
	unsigned int   entry_index = 0;

	if (index != NULL) {
    	*index = entry_index;
    entry_index = sizeof(int);
    // etc. etc.