This version is outdated by a newer approved version.This version (2017/06/16 16:02) was approved by zdimension.The Previously approved version (2017/03/25 16:01) is available.
This is an old revision of the document!
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 | −27 which equals −128 | 27 − 1 which is equal to 127 |
uint8_t | Unsigned | 8 | 1 | 0 | 28 − 1 which equals 255 |
int16_t | Signed | 16 | 2 | −215 which equals −32,768 | 215 − 1 which equals 32,767 |
uint16_t | Unsigned | 16 | 2 | 0 | 216 − 1 which equals 65,535 |
int32_t | Signed | 32 | 4 | −231 which equals −2,147,483,648 | 231 − 1 which equals 2,147,483,647 |
uint32_t | Unsigned | 32 | 4 | 0 | 232 − 1 which equals 4,294,967,295 |
int64_t | Signed | 64 | 8 | −263 which equals −9,223,372,036,854,775,808 | 263 − 1 which equals 9,223,372,036,854,775,807 |
uint64_t | Unsigned | 64 | 8 | 0 | 264 − 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;