title: How does preprocessing and the search paths in c++ work?
body: <p>I have a clang.C file:</p>
  <pre><code>#include &quot;A.h&quot;
  #include &quot;B.h&quot;
  
  int main(int argc, char* argv[])
  {
     return 1;
  }
  </code></pre>
  <p>I also have these include paths, which will be passed in order to the compiler arguments:</p>
  <pre><code>/path/to/B.h
  /path/to/A.h
  /different/path/to/B.h  &lt;-- duplicate file
  </code></pre>
  <p>When I add all 3 paths (in order) to my preprocessor statement and run it, I get this:</p>
  <pre><code># 1 &quot;clang.C&quot;
  # 1 &quot;&lt;built-in&gt;&quot;
  # 1 &quot;&lt;command-line&gt;&quot;
  # 1 &quot;/usr/include/stdc-predef.h&quot; 1 3 4
  # 1 &quot;&lt;command-line&gt;&quot; 2
  # 1 &quot;clang.C&quot;
  # 1 &quot;/path/to/A.h&quot; 1
  # 2 &quot;clang.C&quot; 2
  # 1 &quot;/path/to/B.h&quot; 1
  # 3 &quot;clang.C&quot; 2
  
  int main(int argc, char* argv[])
  {
     return 1;
  }
  </code></pre>
  <p>I expect that the <code>/path/to/B.h</code> line should be <code>/differnt/path/to/B.h</code> since the pointer skips over <code>/path/to/B.h</code> and is at <code>/path/to/A.h</code>. When it needs to read <code>B.h</code>, is starts from <code>/path/to/A.h</code>, doesn't find it, then goes to the next <code>-I</code> path included, which would be <code>/different/path/to/B.h</code>. Is this how preprocessing works? If not, could someone explain it correctly?</p>