From 70884a882eae5f090871ec733bc8f53055ca399b Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Thu, 28 Jul 2016 19:07:14 +1000 Subject: [PATCH] adding brief code-style section to Developer_tips --- docs/Developer_tips.md | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/Developer_tips.md b/docs/Developer_tips.md index 7de7d11b..4d563455 100644 --- a/docs/Developer_tips.md +++ b/docs/Developer_tips.md @@ -19,3 +19,49 @@ C functions defined within `shared/` must also be bound by a file within `lisp/` more information on this will be provided in this document later. +Code formatting +--------------- + +C code is automatically formatted using `clang-format`, +if you have `clang-format` installed you can invoke the formatter via running: + + # from the top level directory + $ cmake . + $ make format + +It is recommend that you format your code before making a pull request, +although semi-regular formats are run to catch any code that wasn't +pre-formatted. + + +A quick outline of the C style: + + - 2 space indent + - Never use tabs + - No column width limit + + +A very short example showing some of the features of this style + + int main(int argc, char **argv) { + int a = 14; + int *b = &a; + + switch(a) { + case 14: + puts("a was 14") + break; + + default: + puts("I have no idea what happened") + break; + } + + if(*b > 5) { + puts("*b is bigger than 5") + } + else { + puts("*b is not bigger than 5") + } + } +