3

When you write #include "foo.h" I would expect the compiler to check the directory of the file doing the including (as opposed to the current directory) first, and if not found there then fall back on a search of the list of paths as in the case of #include <foo.h>.

Unless an absolute path was specified, #include "/foo.h", in which case only the absolute path needs to be checked.

Are there any C compilers where the rules are different?

4
  • i am using gcc but the rules are same which you have listed..! i think including such files are part of c-language stuff isnt it? Commented Oct 4, 2011 at 8:41
  • 1
    Oddly enough no, the language spec says it's implementation defined. That's why I want to check if any implementations do otherwise. Commented Oct 4, 2011 at 8:47
  • 1
    oh then +1 to you...may be some cross-compilation tool chain do in some other way..!! o/w gcc ,sun studio,visual studio,turbo's compiler, all follow this rules. Commented Oct 4, 2011 at 8:53
  • 1
    The standard cannot define how to search directories, as that would limit the implementation to systems that actually have directories in their file system. Or have a file system... Commented Oct 4, 2011 at 16:42

1 Answer 1

3

Kernighan & Ritchie write:

[#include "foo"] searches first in association with the original source file (a deliberately implementation-dependent phrase), and if that search fails, then as in the first form.

Which means, make no assumption on the search strategy for quotes. However, all compilers I have run into share the praxis of searching in the including file's path first, and falling back to the compiler's search path if not found.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.