This version (2017/06/16 18:29) was

*approved*by zdimension.The Previously approved version (2017/06/12 01:52) is available.### Table of Contents

# Code formatting conventions

## Wiki

To insert code, use the `<code cpp>`

tag.

## Casing

**Macros**:`SCREAMING_SNAKE_CASE`

**Structures / Types / Constants / Enum members**:`PascalCase`

**Variables / Fields**:`camelCase`

## Indentation

Thou shalt in all of thy code let ye Allman's style brace indentation be used (i.e. braces should always be on their own line, no matter if `struct`

, `if`

, `while`

, etc.)

struct MyStruct { int32_t uselessField; uint16_t anotherUselessField; }

## Type names

When defining fields of number type, you must use the types defined in `stdint.h`

:

Specifier | Signing | Bits | Bytes | Minimum Value | Maximum Value |
---|---|---|---|---|---|

`int8_t` | Signed | 8 | 1 | −2^{7} which equals −128 | 2^{7} − 1 which is equal to 127 |

`uint8_t` | Unsigned | 8 | 1 | 0 | 2^{8} − 1 which equals 255 |

`int16_t` | Signed | 16 | 2 | −2^{15} which equals −32,768 | 2^{15} − 1 which equals 32,767 |

`uint16_t` | Unsigned | 16 | 2 | 0 | 2^{16} − 1 which equals 65,535 |

`int32_t` | Signed | 32 | 4 | −2^{31} which equals −2,147,483,648 | 2^{31} − 1 which equals 2,147,483,647 |

`uint32_t` | Unsigned | 32 | 4 | 0 | 2^{32} − 1 which equals 4,294,967,295 |

`int64_t` | Signed | 64 | 8 | −2^{63} which equals −9,223,372,036,854,775,808 | 2^{63} − 1 which equals 9,223,372,036,854,775,807 |

`uint64_t` | Unsigned | 64 | 8 | 0 | 2^{64} − 1 which equals 18,446,744,073,709,551,615 |

Also, when defining pointer fields, the `*`

must be on the right-side:

uint32_t *fieldName;

instead of

uint32_t* fieldName;

## Bit fields

### Horizontal (long descriptions)

#### 8-bit

Hex | Bit | Description |
---|---|---|

`0x0001` | 0 | text |

`0x0002` | 1 | text |

`0x0004` | 2 | text |

`0x0008` | 3 | text |

`0x0010` | 4 | Example of double line |

Example of double line | ||

`0x0020` | 5 | text |

`0x0040` | 6 | text |

`0x0080` | 7 | text |

#### 16-bit

Hex | Bit | Description |
---|---|---|

`0x0001` | 0 | text |

`0x0002` | 1 | text |

`0x0004` | 2 | text |

`0x0008` | 3 | text |

`0x0010` | 4 | Example of double line |

Example of double line | ||

`0x0020` | 5 | text |

`0x0040` | 6 | text |

`0x0080` | 7 | text |

`0x0100` | 8 | text |

`0x0200` | 9 | text |

`0x0400` | 10 | text |

`0x0800` | 11 | text |

`0x1000` | 12 | text |

`0x2000` | 13 | text |

`0x4000` | 14 | text |

`0x8000` | 15 | text |

### Vertical (field names only)

Hex value | `0x8000` | `0x7F00` | `0x001F` |
|||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

Bit | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |

Field | `Field1` | `Field2` | `Field3` |