This version (2017/06/16 16:29) was approved by zdimension.The Previously approved version (2017/06/11 23:52) is available.Diff

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 :

SpecifierSigningBitsBytesMinimum ValueMaximum Value
int8_tSigned 8 1−27 which equals −12827 − 1 which is equal to 127
uint8_tUnsigned 8 1028 − 1 which equals 255
int16_tSigned 16 2−215 which equals −32,768215 − 1 which equals 32,767
uint16_tUnsigned 16 20216 − 1 which equals 65,535
int32_tSigned 32 4−231 which equals −2,147,483,648231 − 1 which equals 2,147,483,647
uint32_tUnsigned 32 40232 − 1 which equals 4,294,967,295
int64_tSigned 64 8−263 which equals −9,223,372,036,854,775,808263 − 1 which equals 9,223,372,036,854,775,807
uint64_tUnsigned 64 80264 − 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 TR4 only Example of double line
TR5 only 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 TR4 only Example of double line
TR5 only 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
wiki/conventions.txt · Last modified: 2017/06/16 16:28 by zdimension
Back to top
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0