From faf7237abfed7fa1c41a8ce0b2b53fde9eeb44a6 Mon Sep 17 00:00:00 2001 From: Valentine Sinitsyn Date: Sun, 26 Oct 2014 18:07:26 +0500 Subject: [PATCH] Documentation: Introduce coding style As the number of external contributions to Jailhouse grows, the need for some formal coding style to ease review process and integration arise. This is the first attempt to summarize what's have been discussed on jailhouse-dev@googlegroups.com mailing list so far. Signed-off-by: Valentine Sinitsyn [Jan: clarify include block separation] Signed-off-by: Jan Kiszka --- Documentation/coding-style.txt | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Documentation/coding-style.txt diff --git a/Documentation/coding-style.txt b/Documentation/coding-style.txt new file mode 100644 index 0000000..7fcbfeb --- /dev/null +++ b/Documentation/coding-style.txt @@ -0,0 +1,42 @@ +Coding style +============ + +This document sets the coding style for Jailhouse code contributions. +In general, Jailhouse coding style for C is the same as for Linux kernel +(checkable with scripts/checkpatch.pl and detailed in +Documentation/CodingStyle), but with some notable variations and clarifications +described here (in random order): + +* Align function arguments vertically when wrapping over line breaks: + + void rather_long_function_name(struct another_rather_long_name *argument1, + struct yet_another_long_name *argument2); + +* Avoid conditional compilation (#ifdefs) where possible (and it's almost + always possible). Variations should be resolved during link time, or + (if absolutely necessary) in the runtime (but think about performance). + +* Do not explicitly initialize static variables you want zeroed. C standard + ensures this by default. + +* Do not insert blank lines in #include list, except to separate include blocks + where the second depends on the first one, e.g. + + #include + + #include + +* Always include generic headers ("jailhouse/*.h") before architecture + headers ("asm/*.h"). + +* Header files must be self-standing, i.e. must not rely on other headers being + included prior to them. Use scripts/header_check to validate. + +* Spaces in brackets are permitted for designated initializers in order to + improve readability via vertical alignment: + + [ 0/8 ... 0x1f/8] = 0, /* floppy DMA controller */ + [ 0x20/8 ... 0x3f/8] = -1, + [ 0x40/8 ... 0x47/8] = 0xf0, /* PIT */ + +For Python code, stick to PEP-8. -- 2.39.2