After ')', ','
This document describes the coding style used in cinit.
Indent the code by 3 spaces for each level. Indent variable names, so the names begin all at the same position. Use three spaces to place them.
Where to put or avoid whitespaces (space or linefeed (lf)).
After closing brace "if(test) return 0;"
Spaces before and after =, >, <, ==, !=', >=, <=, >>, <<, &, &&, |, ||
After start of comment and before end of comment: / text /
After ')', ','
Within braces and code "(!test)",
Before braces "if(code)"
No space before ), so if )), do not put a space after the first )
This somehow includes the setting of braces (indirectly through (not) setting spaces.
Put the if, the braces and the opening curly brace on one line, put the closing one together with else and the new opening curly brace on one line:
if(...) { /* code */ } else { /* else: code */ }
while(condition) { /* repeat */ }
do { /* something */ } while(running);
switch(value) { case DO_SOMETHING: /* code */ break; default: break; }
Opening and closing curly braces are placed on a seperate row:
int func(int params) { body }
See above.
where necessery, do not state the obvious in comments:
/* this code increments tmp */ ++tmp;
If there is more than one line containing a comment, try to adjust them so they look the same in width and position:
int illuminati = 23; /* do not want to comment that */ int the_answer_to_everything = 42; /* 42. */ [...] while(illuminati < the_answer_to_everything) { /* only try before them */ overtake_world(&self); /* overtake is complex */ }
Put a header into each file, containing:
Date of file being put into existence (year is enough)
Name and e-mail (obfuscated if you want) of the author(s)
Description of the function
Copyright statement (if not included GPLv2 or later is assumed)
Include system headers first, then place own headers. Comment the includes, wherefore you added them. Example:
#include <unistd.h> /* write */ #include "cinit.h> /* cinit_ipc_* */