-
Notifications
You must be signed in to change notification settings - Fork 3
Coding Style for C style languages
This document serves as a reference for the coding style used for this project for C++ and C-family languages. This style will be preferred and any submissions or pull requests that do not respect the style may be removed or turned away from the master repository. Credit should go where credit is due: this page is largely copied over from the Project Tox wiki.
- Indentation
- Breaking long lines and strings
- Placing braces and spaces
- Naming
- Typedefs
- Functions
- Data structures
- Macros, Enums, and RTL
- Allocating Memory
- Inlining
- Function return values and names
Indentation will be tab-centric, and source code should be expected to have tabs for whitespace, not spaces. The recommended spacing is 1 tab = 4 spaces. There are a plethora of text editors and IDEs out there that can do the conversion for you, so this should not bring great difficulty. That said, whitespace at the end of lines is also the devil. Please use a proper editor and remove trailing whitespace at the end of lines where possible.
When dealing with multiple indentation levels like switch statements, the preferred way is to align the switch statement with the subordinate case labels, like so:
switch (suffix) {
case 'G':
case 'g':
mem <<= 30;
break;
case 'M':
case 'm':
mem <<= 20;
break;
case 'K':
case 'k':
mem <<= 10;
/* fall through */
default:
break;
}
It is also important that you place control statements on multiple lines, and use the corresponding indentation appropriately. For example, it is NOT okay to place multiple statements on a single line, and then try to hide the second function as follows:
if (condition) do_this();
do_something_everytime();
Multiple assignments on a single line are not okay either. Make sure your code is readable first, we can optimize later.