Properly use #include <> and #include ""

Michael Olbrich michael-olbrich at web.de
Fri Jun 15 15:21:39 BST 2007


On Fri, Jun 15, 2007 at 03:13:22PM +0200, Matthias Kretz wrote:
> On Friday 15 June 2007, Andreas Pakulat wrote:
> > If I understood correctly a public header in the shell library should
> > use #include "foobar.h" for any header that is also inside the shell
> > library. However it should use #include <barfoo.h> for any system-header
> > and also headers from other libraries of the kdevplatform module. Is
> > that correct? If not, whats the correct way here?
> 
> Just a small correction: You don't have to draw the line between every single 
> library. If two or more libs ship together (e.g. kdecore, kdeui, kio, ...) 
> they should prefer "" to <> to include headers from the other lib because the 
> relative position of the header (when installed) is known. Only when the 
> relative position is not known (e.g. Qt headers and system headers) should 
> you include headers with <>.
> 
> But I've heared different opinions on this, though no arguments to convince 
> me, yet.

Please don't use "" for _any_ installed header. This can result in very
confusing errors.

----- /usr/include/a/foo.h --------
#include "bar.h"
...
-----------------------------------

----- /usr/include/a/bar.h --------
// something
-----------------------------------

----- /usr/include/b/bar.h --------
// something else
-----------------------------------

/usr/include/b/foo.h does _not_ exist.

----- 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. The order in which
headers are included and whether they are included directly or
indirectly (via another header) should never change the result.

Therefore please use <> for all installed headers, whether they are
shipped together or not.

michael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070615/dfb60d25/attachment.sig>


More information about the kde-core-devel mailing list