3 I guess I should document this, it might not be obvious.
5 libcody is implemented in C++11. Because it's used in compiler
6 development, we can't use the latest and greatest.
8 The formatting is close to GNU, but with a few differences.
10 ## Extensions to C++11
12 It uses __VA_OPT__ when available, falling back on GNU's variadic
13 macro `,#` extension. This is in the `Assert` macro, so one can have
14 multi-argument template instantiations there. Not that libcody does
15 that, but this is code I used elsewhere.
19 The underlying formatting is GNU style. Here are a few notes about
20 things that commonly catches programmers unfamiliar with it is:
22 * Spaces between binary operators. Particularly in a function call,
23 between the name and the open paren:
26 Fn (a + b, ary[4], *ptr);
29 In general GNU style uses a lot more whitespace than Clang-style.
30 We're not trying to cram as much code as possible onto a page!
32 * Scope braces are always on a line of their own, indented by 2
33 spaces, if they're a sub-statement of an `if`, `for` or whatever:
43 Conditions and loops containing a single statement should not use `{}`.
44 FWIW this was my personal indentation scheme, before I even met GNU code!
46 * The same is true for a function definition body, except the
57 * Initialization bracing is not like scope bracing. There tends to be
60 * Break lines at 80 chars, this should be /before/ the operator, not after:
71 Thus you can tell what lines are continued from the previous by
72 looking at their start. Use parens to control indentation.
74 If you find yourself wanting to break a line at `.`, don't.
75 Refactor your code to avoid needing that.
77 * Template instantiations and C++ casts should have no space before the `<`:
81 static_cast<T> (arg); // space before the ( though
84 * Pointer and reference types need a space before the `*` or `&`, if
85 the preceding token is ascii text (a cpp-identifier):
93 See below a difference in qualifier placement.
95 * Code should compile without warnings.
101 Unlike GNU code, variants of Camel Case are used. use `PascalCase`
102 for function, type and global variable names. Use `dromedaryCase` for
103 member variables. Block-scope vars can be `dromedaryCase` or
104 `snake_case`, your choice.
108 Type qualifiers go after the thing they qualify. You have to do this
109 for pointers anyway, and read them inside-out, because, C Just being
113 int const foo = 5; // constant int
114 int *const pfoo = nullptr; // constant pointer to int