On Tuesday 05 March 2013 15:06, in comp.lang.c,
ian- wrote:
> James Harris wrote:
>>
>> Sorry - I tried to keep the description short. Let me go the other way
>> and illustrate by using something specific in the form of the
>> directory tree you suggested.
>>
>> Say you wanted to include a header from another directory would you
>> write something along the lines or
>>
>> #include "../../src/utils1/header.h"
>>
>> or would it be better to write
>>
>> #include "header.h"
>>
>> and to add a compile switch along the lines of
>>
>> --header-source ../../src/utils1
>>
>> In either case how is it best to specify the referred-to directories?
>
> It's easier to simply write
>
> #include <utils1/header.h>
>
> and have -I <path to src> as one of your compile options.
which, with GCC, can be dangerous.
Consider, say you have a source-supplied header called
time.h
in your source directory.
When you
#include <time.h>
in your source, you'll get the source-supplied time.h header from your
source directory rather than the system-supplied time.h header from the
standard include directories.
This happens because GCC searches the directories named by the -I
option /before/ it searches the standard system include directories.
(See the GCC instructions on -I for details).
And, yes, I've seen this happen in at least one source package, where the
authors figured that it was simpler to -I their include library (which
included some non-standard headers named with the same names as standard
headers) than it was to
#include "./path/to/application/include/files/header.h"
--
Lew Pitcher
"In Skills, We Trust"