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:

  1. the mikroC PRO for ARM installation folder › “include” folder
  2. user's custom search paths

The "header_name" version specifies a user-supplied include file; the mikroC PRO for ARM will look for the header file in the following locations, in this particular order:

  1. the project folder (folder which contains the project file .mcarm)
  2. the mikroC PRO for ARM installation folder › “include” folder
  3. 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.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code