[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Properly use #include <> and #include ""
From:       Hans Meine <hans_meine () gmx ! net>
Date:       2007-06-15 14:41:39
Message-ID: 200706151641.39988.hans_meine () gmx ! net
[Download RAW message or body]

Am Freitag, 15. Juni 2007 16:21:39 schrieb Michael Olbrich:
> Please don't use "" for _any_ installed header. This can result in very
> confusing errors.

This is the first time I hear that.

> ----- /usr/include/a/foo.h --------
> #include "bar.h"
OK, clearly the programmer meant /usr/include/a/bar.h here.

> ----- test1.c ---------------------
> #include <foo.h>
> ...
> -----------------------------------
>
> ----- test2.c ---------------------
> #include <bar.h>
> #include <foo.h>
> ...
> -----------------------------------
>
> compiling with -I/usr/include/b/ -I/usr/include/a/ gets different
> results for test1.c and test2.c. That is imho wrong.
Why?  test2.c and test1.c *are* different.

I am not sure what "error" should happen here (I only see an extra include 
which probably populates the namespace), but maybe that is because you did 
not tell us about the include guards within the header files.  Something 
strange may happen if both foo.h's use the same include guards, but then they 
probably come from the same library, and you should have only one of the dirs 
in the include path (and /usr/include/b/foo.h would exist, too).

Normally, using #include "..." is the preferred way to include header files 
from the same library AFAIK, since you know exactly which file you mean.
A definite advantage is that it does not matter whether the program does
#include <QtGui/QWidget> and is compiled with -I$(QTDIR)/include or whether it 
uses #include <QWidget> together with -I$(QTDIR)/include/QtGui.

Ciao, /  /
     /--/
    /  / ANS
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic