On Thu, 2015-01-29 at 10:05 -0500, Justin Ross wrote:
> The Proton C code has a lot of redundant includes.  That is, headers often
> directly include items they already have transitively.  This makes some of
> the dependency graphs in our api doc less attractive and less helpful:
> 
I think this is a problem with the doc generator mostly, not the actual
header files.

The current best practice in C (and C++) is for a header file (and a
source file too) to include any header that defines a type that the file
directly depends on (irrespective of any transitive includes).

This makes the file robust against any change of transitive includes
because the dependencies of its dependencies change.

So I agree with Alan, we should remove _unnecessary_ includes but not
ones that are redundant because of transitive includes.

Another point is that you should only need to include a header file for
a type if you are using details of the type's structure not if you
merely use a pointer to that type in an API - that can be covered with a
forward declaration of the type like "typedef struct pn_foo pn_foo;".

In general the C headers should have few reasons to need the details of
other complex types.

One reason why C headers very often do not follow these rules is that
people usually just compile source files and generally do not check that
header files compile on their own.

Andrew



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to