[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why not #include "config.h"?

From: Ralf Wildenhues
Subject: Re: why not #include "config.h"?
Date: Tue, 22 Sep 2009 22:35:44 +0200
User-agent: Mutt/1.5.20 (2009-08-09)

* Steffen Dettmer wrote on Tue, Sep 22, 2009 at 05:06:41PM CEST:
> I though this was a kind of lazyness; just used "" and <>
> interchangingly without deeper meaning?

You can do that only as long as there is at most one header file with
that name involved.

> I tought correct is:
> - with -I (and gcc), #include "config.h" is correct and works
> - with -I (and gcc), #include <config.h> is not correct but works
>   anyway, because gcc searches system headers in user directories
>   if it was not found in system directories

Not AFAIK.  It works because automake adds -I. by default.

> - if #include <config.h> is really desired, I think for gcc it
>   would be correct to use -isystem $(top_builddir)

No, don't use -isystem.  It is not intended for this situation.

> - for other compilers, -I often is -I but -isystem can be -j

-I is accepted by all unixoid compilers, not just GCC.  -isystem
is not standardized.

> - other compilers may not distinguish that much or that flexible
>   or not configurable where <file.h> is searched

Which compiler(s) are you thinking of?  Thanks.

> - on other compilers, #include <config.h> may not even work
>   (when they use a fixed system directory and support no fallback
>   search to user directories)

Again, do you have examples?

> Could * please correct my assumptions?

Quoting the SUSv3 manpage for c99:

 -I  directory
      Change the algorithm for searching for headers whose names are not
      absolute pathnames to look in the directory named by the directory
      pathname before looking in the usual places. Thus, headers whose names
      are enclosed in double-quotes ( "" ) shall be searched for first in the
      directory of the file with the #include line, then in directories named
      in -I options, and last in the usual places. For headers whose names are
      enclosed in angle brackets ( "<>" ), the header shall be searched for
      only in directories named in -I options and then in the usual places.
      Directories named in -I options shall be searched in the order
      specified. Implementations shall support at least ten instances of this
      option in a single c99 command invocation.

This means,
  #include "config.h"

would, even with
  c99 -I. -I$(srcdir) -c $(srcdir)/foo.c

try to open $(srcdir)/config.h before trying to open ./config.h.  That
would be wrong, however unlikely it would be to have config.h files in
both the build and the source tree.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]