File: CODINGSTYLE

package info (click to toggle)
dwarfutils 20180809-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,228 kB
  • sloc: ansic: 63,382; sh: 5,222; cpp: 4,041; makefile: 548; python: 445; awk: 11
file content (71 lines) | stat: -rw-r--r-- 2,776 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
This document is a brief description of the main
coding style conventions in libdwarf.   Many of them
will be obvious from the code, but over time some
accidental diffences crept in.

Code should be indented in multiples of 4 spaces, and
tabs should not be used to indent the source code.
Use the dicheck program to check indenting.

dwarf.h and libdwarf.h must have all arguments commented
out as these are public headers.  Because a  prototype like
int dwarf_example_prototype(Dwarf_Debug foo);
would be made unusable by  a legitimate
preprocessor definition
such as  #define foo +

The struct naming convention is 'struct  Camel_Caps_s' for the
struct and   'Camel_Caps' for any typedef for the struct.
Admittedly having both camel caps
and an underbar is an unusual convention, but it is
the way the coding was begun in the early 1990's and
we should remain consistent now.

All user-referenceable data and functions 
and user_visible types should begin with DW_ or
dwarf_.  Non-static libdwarf global data and functions
should begin with _dwarf (a somewhat questionable
approach, but workable).

Function names should be all lower case with underbars
for readability.

There should never be static data in any function.
Nor should there ever be static data outside of libdwarf
functions.  libdwarf can be called from multiple threads
(but only from one thread per Dwarf_Debug) and multiple
Dwarf_Debug objects can be open at one time.
Instead place such data per-dbg into the Dwarf_Debug structure
in dwarf_opaque.h. Similarly for the producer code.

Function-local variables should be lower-case with
underbars for readability.   It's ok for a small loop
with counters to use single letter names like i or k or m.

structure members should have a struct-specific
2-character prefix to the name (followed by
an underbar). That makes it much
easier to grep for uses of members.

Try to keep lines under 80 characters in length.

Ensure every if() has {} to enclose the actions.

There is a slight preference for if<single space>(
over  if(. Similarly with for (, while (, and switch (.
Not obsessing about these space-issues...

Use libdwarf.h types for all the data objects you define,
though sometimes an 'unsigned' or 'int' or 'size_t' is
ok in restricted circumstances.  Dwarf_Unsigned Dwarf_Signed
are the preferred integer types for general use.

No .c file should ever have an 'extern *' to access some external.
Instead, such external references should be defined in a header file
and every .c with a reference to the external should #include
the relevant header.  Being obsessive about this ensures that when
the definition changes it will match the function declaration.
There are a couple violations of this as of 2012, and those
should be fixed!

------------