Skip to content
mkind edited this page Oct 19, 2015 · 1 revision

At A Glance

We're trying to be compliant to the FreeBSD coding style. However, we have some rules that differ. In addition to that, we use the CERT Secure Coding Standard.

Details

Layout

  • two spaces indentation
  • 80 Characters per line
  • Only use multi line comments like /* foo */. Please do not use //.

Pointer

  • use char *foo instead of char * foo or char* foo

Strings

  • Use the string typedef in sb-common.h instead of char * if yout want to use strings. We introduced this structure, because C strings do not carry information about their length. We think, this is error prone. To convert a char * into a string, use can the helper functions cstring_to_string or cstring_copy_string.

Functions

  • We use the following style for function definitions (differs from the FreeBSD style). Here, the return value is on the same line like the rest. This makes the code better grep-able.

having the return value in the same line makes it grep-able:

int foo (int x)
{
  /* Some code */
}

Function Return Values and Exit Codes

  • a function should return a return code indicating whether the execution succeeded. Usually they return an int. A return (0) indicates success while a negative number indicates an error.
  • every return value, must be verified
  • explicit checks preferred since they make it easier to understand the code.

explicitly checking a function's return value is good practice:

if (foobar() != 0 ) { 
 /* error handling */
 ...
}
Clone this wiki locally