-
Notifications
You must be signed in to change notification settings - Fork 40
Coding Guidelines
Install a Git pre-commit hook to automatically check for tab and whitespace errors before committing. In the root directory of your local Git repository do
mv .git/hooks/pre-commit.sample .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
The repository contains a .gitattributes
file, which sets the appropriate level of whitespace checks for each file. The following will be treated as errors:
- whitespace at the end of a line
- blank lines at EOF
- mixing tabs and whitespace in indents
In all files but Makefiles tabs generally are not allowed for indentation.
Please configure your editor to strip trailing whitespace when you save a file.
-
Indentation by spaces only (no tabs) with two spaces per level.
-
Opening braces on the same line as the statement creating the scope (K&R style, not ANSI):
routine (args) { if ( i>0 ) { ... } for ( i=0; i<N; i++ ) { ... } }
-
Lines should not exceed 72 characters.
-
Function return type on same line as remaining function signature.
-
A space after the function name in a function call/definition and after the keywords for and if. No extra spaces for functions inside the braces enclosing arguments (but spaces between arguments, after the comma). Extra spaces inside the brackets after for and if.
// no space int x = f (par1, par2, par3); // space if ( condition ) for ( ; ; )
-
One-line comments introduced with //
-
No trailing white space.