[libdvbpsi-devel] Header multiple inclusion error

Jean-Paul Saman jpsaman at videolan.org
Tue May 14 13:29:45 CEST 2013


On Tue, May 14, 2013 at 11:29 AM, Andrey Utkin <
andrey.krieger.utkin at gmail.com> wrote:

> 2013/5/14 Jean-Paul Saman <jpsaman at videolan.org>:
> > Andrey,
> >
> > On Sat, May 11, 2013 at 10:54 PM, Andrey Utkin
> > <andrey.krieger.utkin at gmail.com> wrote:
> >>
> >> I consider forcing compilation fail in case of multiple inclusion not
> >> correct.
> >> You can see in other projects include guards without "else" block,
> >> which result in silently compiling and working correctly.
> >> To further justify my position, i'll give an example.
> >> We have two classes - A and B, both of which utilize some dvbpsi
> >> objects, let's say dvbpsi_t, in their data members or function
> >> signatures. Thus they both have to include dvbpsi.h in their .h files.
> >> Then we have class C, which includes A and B as data members, so it
> >> has to include A.h and B.h in its .h. Voila, multiple inclusion, and
> >> libdvbpsi forces compilation fail.
> >
> >
> > You should not include the dvbpsi.h header files inside the .h file for
> this
> > situation. Include it only in the
> > .c files is the right solutions in your example.
>
> Could you please explain what is the problem/risk of applying the
> change i proposed and using libdvbpsi the way i described? Currently I
> see none.
>

In case of multiple inclusion of a header file is usually a sign that the
design is flawed.
Your design probably exposes more internal details than it needs too.

It could easily lead to circular dependencies. It is cleaner to have header
files as much
as possible declared inside the *.c file.

This is my 2cts on the subject.

And with workaround you gave, i see the problem of having type
> dvbpsi_t undefined in headers. As i explained, i need this type as
> classes datamembers.
>

You could do this:

file a.c

#include <dvbpsi.h>
#include "a.h"

/* .. other stuff ...  */

Then file b.c

#include <dvbpsi.h>
#include "b.h"

/* .. other stuff ... */

And finally: file "c.c"

#include <dvbpsi.h>
#include "a.h"
#include "b.h"
#include "c.h"

/* other stuff */


> --
> Andrey Utkin
>

Kind regards,

Jean-Paul Saman.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/libdvbpsi-devel/attachments/20130514/aff97235/attachment.html>


More information about the libdvbpsi-devel mailing list