#33 File Include variant


Hi Rich,

> If you have further questions, please feel free to add them here.
Hopefully this doesn't seem like spamming, but you checked "Close comment posting" for the other ticket, so I need to create a new one ;)
Reference: https://sourceforge.net/tracker/?func=detail&atid=396647&aid=2989216&group_id=29557

> potential ambiguity
With "" There is a fixed sequence in which the preprocessor looks for the file. It first starts searching in the directory that holds the sourcefile using an "#include". If it is found, it stops, so there is no ambiguity for users.

So from a library user's point of view using "" doesn't seem to introduce any drawbacks, but at least saves one precondition (project include path). Looking at the style of the library as a whole, avoiding dependencies seems to be a major design goal?

Regards, ZenJu


  • Richard Sposato

    Richard Sposato - 2010-04-20
    • priority: 5 --> 1
    • assigned_to: nobody --> rich_sposato
  • Richard Sposato

    Richard Sposato - 2010-04-20

    Hi ZenJu,

    I just checked the "2989216" feature request to see if commenting is closed. I don't see that box as checked. If I inadvertently checked, then sorry about the inconvenience.

    Yes, reducing dependencies is a major design criteria of how some parts of Loki are implemented. But this design goal is at odds with another design goal - making some parts of Loki use other parts of Loki. (e.g. - SmartPtr.h depends on SmallObj.h which depends on Singleton.h)

    I don't see how using the double-quote style of #include saves users from having to specify an include path for their MSVC projects. When the compiler see the double-quote #include, it first looks for the included file in the same directory as the source file - not the same directory as the header file. Let's put it this way. You have a source code file which includes a Loki header file, and that Loki header file includes another Loki header file, and you want Loki header files to use the double-quote style of including.

    So let's say your source code file is here:
    and let's say Loki header files are here:

    Let's say YourSource.cpp includes loki/SmartPtr.h. If loki/SmartPtr.h uses the double-quote style to include "SmallObj.h", the compiler will first look inside C:/YourProject for SmallObj.h. On the other hand if loki/SmartPtr.h uses the bracket style to include <loki/SmallObj.h>, then the compiler will only check the include paths, and know not to first look in C:/YourProject. What you are asking me to do is change Loki so your compiler first looks in your own source code directory for Loki header files.

    I think that example makes it very clear that the double-quote style is not the appropriate style for how Loki header files should include other Loki header files.



  • zhnmju123

    zhnmju123 - 2010-04-20

    > the compiler will first look inside C:/YourProject for SmallObj.h
    According to the documentation of MSVC as well as GCC the actual behavior is different:
    E.g.: MSVC: http://msdn.microsoft.com/en-us/library/36k2cdd4\(VS.80).aspx

    Quoted form:
    "This form instructs the preprocessor to look for include files in the same directory of the file that contains the #include statement, and then in the directories of any files that include (#include) that file. The preprocessor then searches along the path specified by the /I compiler option, then along paths specified by the INCLUDE environment variable.
    [...] The preprocessor stops searching as soon as it finds a file with the given name."

    Consequently the compiler will first look in "C:/Loki/include/loki" for "SmallObj.h", find it, and stop further searching. Only if it were not found there, it would search in "C:/YourProject".

  • Richard Sposato

    Richard Sposato - 2010-04-25

    Hi ZenJu,

    Thanks for checking the documentation for MSVC and GCC. My recollection was quite different. I am surprised at what you found especially since I found documentation earlier which says the include path is from the source code file rather than the most recently included header file.

    I also made a little test project to check include paths and discovered the policy is not as originally assumed for MSVC.

    Additionally, I checked some other open source and proprietary projects to see which form of include they use. Some use the double-quote style while other use the bracket style - usually with no explanation as to why one form is favored over the other.

    Let me check with some other folks and get back to you later on this topic.

    Thanks for your patience.



  • zhnmju123

    zhnmju123 - 2010-04-26

    Cool, thank you!


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks