| C Preprocessor & Macro |
| |
| File inclusion |
| |
| The preprocessor directive #include is an instruction to read in the entire contents of another file at that point. |
| |
| This is generally used to read in header files for library functions. Header files contain details of functions and types used within the library. |
| |
| It must be included before the program can make use of the library functions. |
| |
| Library header file names are enclosed in angle brackets, < >. These tell the preprocessor to look for the header file in the standard location for library definitions. |
| |
| Example:
#include |
| |
| another use for #include for the programmer is where multi-file programs are being written. |
| |
| Certain information is required at the beginning of each program file. This can be put into a file called globals.h and included in each program file. |
| |
| Local header file names are usually enclosed by double quotes, " ". It is conventional to give header files a name which ends in .h to distinguish them from other types of file. |
| |
| Our globals.h file would be included by the following line. #include "globals.h" |
| |
| |
| |
| |
| |