-
Notifications
You must be signed in to change notification settings - Fork 7
Coding Conventions
mkind edited this page Oct 19, 2015
·
1 revision
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.
- two spaces indentation
- 80 Characters per line
- Only use multi line comments like
/* foo */
. Please do not use//
.
- use
char *foo
instead ofchar * foo
orchar* foo
- Use the
string
typedef insb-common.h
instead ofchar *
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 achar *
into a string, use can the helper functionscstring_to_string
orcstring_copy_string
.
- 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 */
}
- a function should return a return code indicating whether the execution succeeded. Usually they return an
int
. Areturn (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 */
...
}