Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (27 sloc) 1.3 KB
JOS CODING STANDARDS
It's easier on everyone if all authors working on a shared
code base are consistent in the way they write their programs.
We have the following conventions in our code:
* No space after the name of a function in a call
For example, printf("hello") not printf ("hello").
* One space after keywords "if", "for", "while", "switch".
For example, if (x) not if(x).
* Space before braces.
For example, if (x) { not if (x){.
* Function names are all lower-case separated by underscores.
* Beginning-of-line indentation via tabs, not spaces.
* Preprocessor macros are always UPPERCASE.
There are a few grandfathered exceptions: assert, panic,
static_assert, offsetof.
* Pointer types have spaces: (uint16_t *) not (uint16_t*).
* Multi-word names are lower_case_with_underscores.
* Comments in imported code are usually C /* ... */ comments.
Comments in new code are C++ style //.
* In a function definition, the function name starts a new line.
Then you can grep -n '^foo' */*.c to find the definition of foo.
* Functions that take no arguments are declared f(void) not f().
To set up the basic indentation style in Emacs,
(c-add-style "jos" '("bsd" (indent-tabs-mode . t)))
(add-hook 'c-mode-hook
(lambda ()
(when (string-match "/lab/" buffer-file-name) (c-set-style "jos"))))