]> rtime.felk.cvut.cz Git - jailhouse.git/blob - Documentation/coding-style.txt
Documentation: Add how-to for non-root Linux cells
[jailhouse.git] / Documentation / coding-style.txt
1 Coding style
2 ============
3
4 This document sets the coding style for Jailhouse code contributions.
5 In general, Jailhouse coding style for C is the same as for Linux kernel
6 (checkable with scripts/checkpatch.pl and detailed in
7 Documentation/CodingStyle), but with some notable variations and clarifications
8 described here (in random order):
9
10 * Align function arguments vertically when wrapping over line breaks:
11
12     void rather_long_function_name(struct another_rather_long_name *argument1,
13                                    struct yet_another_long_name *argument2);
14
15 * Avoid conditional compilation (#ifdefs) where possible (and it's almost
16   always possible). Variations should be resolved during link time, or
17   (if absolutely necessary) in the runtime (but think about performance).
18
19 * Do not explicitly initialize static variables you want zeroed. C standard
20   ensures this by default.
21
22 * Do not insert blank lines in #include list, except to separate include blocks
23   where the second depends on the first one, e.g.
24
25     #include <jailhouse/types.h>
26
27     #include <jailhouse/cell-config.h>
28
29 * Always include generic headers ("jailhouse/*.h") before architecture
30   headers ("asm/*.h").
31
32 * Header files must be self-standing, i.e. must not rely on other headers being
33   included prior to them. Use scripts/header_check to validate.
34
35 * Spaces in brackets are permitted for designated initializers in order to
36   improve readability via vertical alignment:
37
38     [     0/8 ...   0x1f/8] = 0, /* floppy DMA controller */
39     [  0x20/8 ...   0x3f/8] = -1,
40     [  0x40/8 ...   0x47/8] = 0xf0, /* PIT */
41
42 For Python code, stick to PEP-8.