Blame libdwarf/CODINGSTYLE

Packit cdaae3
This document is a brief description of the main
Packit cdaae3
coding style conventions in libdwarf.   Many of them
Packit cdaae3
will be obvious from the code, but over time some
Packit cdaae3
accidental diffences crept in.
Packit cdaae3
Packit cdaae3
Code should be indented in multiples of 4 spaces, and
Packit cdaae3
tabs should not be used to indent the source code.
Packit cdaae3
Use the dicheck program to check indenting.
Packit cdaae3
Packit cdaae3
dwarf.h and libdwarf.h must have all arguments commented
Packit cdaae3
out as these are public headers.  Because a  prototype like
Packit cdaae3
int dwarf_example_prototype(Dwarf_Debug foo);
Packit cdaae3
would be made unusable by  a legitimate
Packit cdaae3
preprocessor definition
Packit cdaae3
such as  #define foo +
Packit cdaae3
Packit cdaae3
The struct naming convention is 'struct  Camel_Caps_s' for the
Packit cdaae3
struct and   'Camel_Caps' for any typedef for the struct.
Packit cdaae3
Admittedly having both camel caps
Packit cdaae3
and an underbar is an unusual convention, but it is
Packit cdaae3
the way the coding was begun in the early 1990's and
Packit cdaae3
we should remain consistent now.
Packit cdaae3
Packit cdaae3
All user-referenceable data and functions 
Packit cdaae3
and user_visible types should begin with DW_ or
Packit cdaae3
dwarf_.  Non-static libdwarf global data and functions
Packit cdaae3
should begin with _dwarf (a somewhat questionable
Packit cdaae3
approach, but workable).
Packit cdaae3
Packit cdaae3
Function names should be all lower case with underbars
Packit cdaae3
for readability.
Packit cdaae3
Packit cdaae3
There should never be static data in any function.
Packit cdaae3
Nor should there ever be static data outside of libdwarf
Packit cdaae3
functions.  libdwarf can be called from multiple threads
Packit cdaae3
(but only from one thread per Dwarf_Debug) and multiple
Packit cdaae3
Dwarf_Debug objects can be open at one time.
Packit cdaae3
Instead place such data per-dbg into the Dwarf_Debug structure
Packit cdaae3
in dwarf_opaque.h. Similarly for the producer code.
Packit cdaae3
Packit cdaae3
Function-local variables should be lower-case with
Packit cdaae3
underbars for readability.   It's ok for a small loop
Packit cdaae3
with counters to use single letter names like i or k or m.
Packit cdaae3
Packit cdaae3
structure members should have a struct-specific
Packit cdaae3
2-character prefix to the name (followed by
Packit cdaae3
an underbar). That makes it much
Packit cdaae3
easier to grep for uses of members.
Packit cdaae3
Packit cdaae3
Try to keep lines under 80 characters in length.
Packit cdaae3
Packit cdaae3
Ensure every if() has {} to enclose the actions.
Packit cdaae3
Packit cdaae3
There is a slight preference for if<single space>(
Packit cdaae3
over  if(. Similarly with for (, while (, and switch (.
Packit cdaae3
Not obsessing about these space-issues...
Packit cdaae3
Packit cdaae3
Use libdwarf.h types for all the data objects you define,
Packit cdaae3
though sometimes an 'unsigned' or 'int' or 'size_t' is
Packit cdaae3
ok in restricted circumstances.  Dwarf_Unsigned Dwarf_Signed
Packit cdaae3
are the preferred integer types for general use.
Packit cdaae3
Packit cdaae3
No .c file should ever have an 'extern *' to access some external.
Packit cdaae3
Instead, such external references should be defined in a header file
Packit cdaae3
and every .c with a reference to the external should #include
Packit cdaae3
the relevant header.  Being obsessive about this ensures that when
Packit cdaae3
the definition changes it will match the function declaration.
Packit cdaae3
There are a couple violations of this as of 2012, and those
Packit cdaae3
should be fixed!
Packit cdaae3
Packit cdaae3
------------