Difference between #include<...> and #include"..."? [duplicate] - c

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is the difference between #include <filename> and #include “filename”?
What is the meaning of include "abc.h" and how it is different from include ?

Including "abc.h" will look in the current directory. <abc.h> will look in the include directory, which can be provided at compile-time.

<abc.h> is usually for built-in use such as math while "abc.h" is usually for customized use.

is being looked for in your header include path and "abc.h" relative to your source file's path first.

Related

#include in header files in embedded [duplicate]

This question already has answers here:
Should I use #include in headers?
(9 answers)
Closed 6 years ago.
I am reading through an embedded C standard book and I noticed the following:
No header file shall contain an #include statement
What should I do with function declarations that have non-standard types?
example: void function(some_funky_type x);
Throw that book away; it is absolute garbage. In fact, you should burn it, to make sure no other poor soul ever picks it up.
Header files should absolutely include all of the header files necessary for them to be self-sufficient. There is nothing worse than trying to carefully massage the order of your #include statements to be sure that the types needed by one are already defined before it is included.
This is a stupid and counterproductive rule for precisely the reason you identified. The alternative is for every .c file to include all of the .h files that a subsequently included header will require. You can imagine that if you introduce a new dependency in a commonly included header that you will now have to update every C file that includes that header.

How to find, from which include file a C preprocessor definition was taken? [duplicate]

This question already has answers here:
How to know (in GCC) when given macro/preprocessor symbol gets declared?
(6 answers)
Closed 7 years ago.
How can I find the include file, from which a certain preprocessor definition was found by GCC?
In a successfully compiling C file, I have a strange macro which I do not understand. For a start, I want to see the file where it comes from. The include hierarchy is very deep; is there an easy way to find the source of the macro?
A wider question has been asked, but the answers tell how to find the definition itself, not its source file.
redefine it before including anything else, the compiler will complain about a redefinition when it encounters it in your header hierachy:
#define MY_PROBLEMATIC_MACRO
#include <the_header.h>
/* code */

How to find definition of library functions in C [duplicate]

This question already has answers here:
Where are the functions in the C standard library defined?
(5 answers)
Closed 7 years ago.
Functions like printf() , scanf() , memset() , puts() etc have their declaration in header files but is there any mechanism to see the definition of these function..?
This might not be a new question but i could not find the appropriate solution for this.
Find your compilers include path (e.g. GCC solution)
Search for the header you are interested in (e.g. printf should be in stdio.h or more likely another header included by stdio.h)
Correctly configured, some IDEs will help you with that, e.g. Eclipse
The method has its limits though, because at some point the include files will get less and less Standard-C, but more and more compiler dependent. The C-standard does not prescribe the contents of standard headers. It merely states that if you write #include <stdio.h>, you can use printf(). That does not necessarily mean that stdio.h has some form you might expect.

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

This question already has answers here:
Closed 10 years ago.
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
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.
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.

Path in includes of C library [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is the difference between #include <filename> and #include “filename”?
I am creating a shared C library. Is there any difference when including
#include <mylib/someheader.h>
versus
#include "mylib/someheader.h"
from *.c or *.h files of this library?
The first version is used for system headers, the second for external headers.
Most compilers will find the right header, whatever the notation, though.
Depends on compiler. Some of them can differ between "system" include path and "just" include path. <> denotes system include path

Resources