diff options
Diffstat (limited to 'share/misc/contrib')
-rw-r--r-- | share/misc/contrib | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/share/misc/contrib b/share/misc/contrib index 6f93fb7..39c9c02 100644 --- a/share/misc/contrib +++ b/share/misc/contrib @@ -21,6 +21,22 @@ is_power_of_two(uint8_t n) return ((n & 0x01) == 0); } +-- +When defining local variables in functions, they +must be declared at the top: + +static void +foo(void) +{ + uint8_t byte; + uint16_t pair; + uint32_t quad; + uint64_t oct; + + ... +} +-- + When checking if an integer is 0 or not, *be explicit* unless it is a bool! Do not do this: @@ -46,6 +62,37 @@ if (!blah) { -- +When writing switch statements, no indentation is needed +before the "case" statement, do this: + +switch (v) { +case 0: + ... + break; +case 1: + ... + break; +case 2: + ... + break; +} + +Not this: + + +switch (v) { +case 0: + ... + break; +case 1: + ... + break; +case 2: + ... + break; +} + +-- Now, only use predefined integer types in sys/cdefs.h like so: uint8_t a; @@ -87,6 +134,14 @@ a pointer, like, for example: uint8_t *ptr = NULL; ... +-- +The preferred pointer style is: + +void *p = ...; + +-- Not: + +void* p = ...; -- or if you have for example, some sort of counter value that must have a start: |