1 \section{C coding style}
3 If you want to submit patches to Ion, you MUST follow my coding
4 style, even if you think it is the root of all evil. We don't want
5 the code to be an incomprehensible mess of styles and I have better
6 things to do than fix other people's style to match mine. The style
7 should be obvious by studying the source, but here's a list of some
8 things to take note of.
10 \subsection{Whitespace}
13 \item Indentations of 4 with \emph{tab size=4}.
15 \item No extra spaces between operators, delimiters etc. except
17 \item around logical and, or (\code{&&}, \code{||})
18 \item around the conditional \code{a ? b : c}
19 \item after commas and semicolons
21 In my opinion this helps pointing out arithmetic or other
22 expressions within logical expressions or parameter lists.
24 \item All kinds of labels are out-tended to the level of the higher
25 level block. For example:
46 \item Opening brace is at the end of the line, except in function
47 bodies, where it is at the beginning of the line following
50 \item Never put the body of a control statement on the same line
51 with the statement (e.g. \verb!if(foo){ bar() }!).
53 For example, the block
55 void foo(int a, int b)
63 has correct style while the block
66 void foo(int a,int b) {
67 if (a == b && c + d == e) {
75 \item The \code{else} keyword follows immediately after the closing brace of
76 previous \code{if}, if any. (This might change so I don't care if you put
79 \item I have used the convention that control statement bodies containing
80 a single statement do not need braces around the block if, in case of
81 the \code{if} all the blocks in \code{if ... else if ... else}
82 contain just one statement. If you want to, just use braces in every
89 \item Function and variable names only have lower case letters. Type
90 names are in mixed case while constants and macros (\code{#define}s)
91 are in upper case letters.
94 \subsection{Miscellaneous}
97 \item In the definition of a pointer variable, the asterisk is attached
98 to the variable name: \code{char *s;}. (One could claim this an
99 exception to the second rule.)
101 \item You might optionally want to use Jed's foldings to group blocks
102 of related code in a file to keep it organized:
105 /*{{{ Many related functions */
118 I think that's mostly it. Study the source when in doubt.