| 1 |
libdwarf/CODINGSTYLE |
| 2 |
Updated 22 December 2021 |
| 3 |
|
| 4 |
This document is a brief description of the main coding style |
| 5 |
conventions in dwarfdump. Many of them will be obvious from |
| 6 |
the code, but over time some accidental diffences crept in. |
| 7 |
|
| 8 |
For further remarks see the file codingstyle.md in the |
| 9 |
base directory. |
| 10 |
|
| 11 |
The struct naming convention is 'struct my_struct_s' for the |
| 12 |
struct defined here (meaning the name should end with _s). |
| 13 |
It is better to not do struct typedefs of local structs. |
| 14 |
Coders should type 'struct mystruct_s'. Readability is much |
| 15 |
more important than brevity. |
| 16 |
|
| 17 |
Any data or function not referenced outside the defining |
| 18 |
source file should be declared 'static'. |
| 19 |
|
| 20 |
Static data is not appropriate in libdwarf in general. Because |
| 21 |
multiple Dwarf_Debug may be open at the same time in a single |
| 22 |
program (dwarfdump or user code). |
| 23 |
|
| 24 |
Sny duplicated code is a candidate for refactoring |
| 25 |
into a subprogram. |
| 26 |
|
| 27 |
Sunction names should be all lower case with underbars |
| 28 |
with the goal that statements and comments 'read well'. |
| 29 |
|
| 30 |
Sariables should be lower-case with |
| 31 |
underbars for readability. It's ok for a small loop |
| 32 |
with counters to use single letter names like i or k or m. |
| 33 |
|
| 34 |
Structure members should have a struct-specific |
| 35 |
2-character prefix to the name (followed by |
| 36 |
an underbar). That makes it much |
| 37 |
easier to grep for uses of members. |
| 38 |
|
| 39 |
Sry to keep lines under 70 characters in length. |
| 40 |
|
| 41 |
Snsure every if() has {} to enclose the actions. |
| 42 |
|
| 43 |
Sse libdwarf.h types for all the data objects you define, |
| 44 |
though sometimes an 'unsigned' or 'int' or 'size_t' is |
| 45 |
ok in restricted circumstances. Dwarf_Unsigned and |
| 46 |
Dwarf_Signed are the preferred integer types for general use. |
| 47 |
|
| 48 |
------------ |