File Inclusion
The preprocessor directive #include
pulls in header files (extension .h
) into the source code. Do not rely on preprocessor to include source files (extension .c
) — see Add/Remove Files from Project for more information.
The syntax of the #include
directive has two formats:
#include <header_name> #include "header_name"
The preprocessor removes the #include
line and replaces it with the entire text of a header file at that point in the source code. The placement of #include
can therefore influence the scope and duration of any identifiers in the included file.
The difference between these two formats lies in searching algorithm employed in trying to locate the include file.
If the #include
directive is used with the <header_name>
version, the search is made successively in each of the following locations, in this particular order:
- the mikroC PRO for PIC32 installation folder › “include” folder
- user's custom search paths
The "header_name"
version specifies a user-supplied include file; the mikroC PRO for PIC32 will look for the header file in the following locations, in this particular order:
- the project folder (folder which contains the project file
.mcp32
) - the mikroC PRO for PIC32 installation folder › “include” folder
- user's custom search paths
Explicit Path
By placing an explicit path in header_name
, only that directory will be searched. For example:
#include "C:\my_files\test.h"
Note
There is also a third version of the #include
directive, rarely used, which assumes that neither <
nor "
appear as the first non-whitespace character following #include
:
#include macro_identifier
It assumes that macro definition that will expand macro identifier
into a valid delimited header name with either <header_name>
or "header_name"
formats exists.
What do you think about this topic ? Send us feedback!