Some coding rule-of-thumbs in pcb-rnd

When writing .h files

Rule 1 Look at the .h file only (ingore any .c); #include everything you need in that given file, directly, to let the compiler understands the structures and function protoypes used there.

Rule 2 Don't be afraid to have redundant #includes (e.g. "a.h is including b.h and c.h while b.h also includes c.h). See also: rule 1 and rule 4.

Rule 3 Circular #include: a.h includes b.h which in turn includes a.h - it is fine, just make sure typedefs and structs are available in the right order (relative to the #include).

Rule 4 Frame your .h code with the usual watchdig #define's as needed:

#ifdef  PCB_FILEA_H
#define PCB_FILEA_H

the code

#endif  /* PCB_FILEA_H */

Rule 6 Use pcb_ or PCB prefixing. E.g. in gtk plugins, PCB_GTK?? according to following table:
Directory Prefix
lib_gtk_common PCB_GTK_
lib_gtk_config PCB_GTK_
hid_gtk PCB_GTK2_
hid_gtk3 PCB_GTK3_

In .c files

Rule 1 Always #include "config.h", and make it the first include (put it before even <stdlib>). This is an essential mechanism for portability.

Rule 2 Source a.c must include it's own header (if there is one), e.g. #include "a.h". This is required to get warnings if API in the header starts to diverge from the implementation.

Rule 3 Look at the .c file only (ingore any .h); #include everything you need in that given file directly. Don't depend on random header files would include what the .c file needs as a side effect - the only exception is the own API definition header of the .c file.

Header rules 2 and 3 from above also apply.

Rule 4 Please do not remove obj_*.h in favor of obj_all.h - obj_all.h is a temporary construct that will be gone. Do not invent such convenient "include all whatever headers" just to reduce the number of includes. Always incldue what you need directly.