Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor Includes, when to use <> or "" [duplicate]

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

like image 955
Mackey18 Avatar asked Mar 05 '26 06:03

Mackey18


2 Answers

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.

like image 153
Reed Copsey Avatar answered Mar 06 '26 20:03

Reed Copsey


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.

like image 27
qwertz Avatar answered Mar 06 '26 18:03

qwertz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!