2

Possible Duplicate:
What is the difference between #include <filename> and #include “filename”?

I've hit a bit of a problem in my C learning, I had a quick search of the questions on this site and couldn't find an answer to this question. It's probably a bit stupid, but here goes.

I've been following some c tutorials and throughout the book all includes have been done like this:

#include <stdio.h>
#include <string.h> etc. etc.

All of a sudden however, they've dropped this bomb shell:

#include <stdio.h>
#include "structSize.h"

With absolutely no explanation as to why "..." was used, I'm completely dumbfounded. Could anyone perhaps provide an explanation as to what is the difference between <...> and "..." and when to use each one.

Thanks for the help.
Regards,
Mike

Community
  • 1
  • 1
Mackey18
  • 2,322
  • 2
  • 25
  • 39

2 Answers2

8

Typically, you use #include "..." for files in your project, and #include <...> for "system" include files.

The difference is in how and where the preprocessor searches for the file based on the name to include. "" syntax will typically search the current file's directory first. The actual search mechanism is compiler specific, however, so you would need to look at your C compiler's documentation for details on what actual paths are used for each option.

For details, see Include Syntax from GCC for one implementation's examples.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • Perfect, thank you. This makes sense as this was the first custom header we had used, and so obviously it wouldn't be a standard, system include. Thanks for clearing this up. Problem solved! I'll mark as answer in a couple of minutes when it allows me to. – Mackey18 Aug 08 '12 at 16:53
2

With "" the file will be searched in the directory where the file which includes something is located, if the include isn't found, the compiler will look in the standart include directory (it's compiler dependent in which folder this is).

With <> the compiler will look directly in the include directory without looking in any other directory.

qwertz
  • 14,614
  • 10
  • 34
  • 46