Keil™, An ARM® Company

Cx51 User's Guide

How #include Works

The #include directive tells the C preprocessor to include the contents of the file specified in the input stream to the compiler and then continue with the rest of the original file.

For example, the header file, file.h contains the following:

char *func (void);

The program file, myprog.c includes this header file:

#include "file.h"

void main (void)
{
while (1)
  {
  printf (func());
  }
}

The output generated by the proprocessor is:

char *func (void);

void main (void)
{
while (1)
  {
  printf (func());
  }
}

Header files typically contain variable and function declarations along with macro definitions. But, they are not limited to only those. A header file may contain any valid C program fragment. However, this practice is error-prone, very confusing, and not at all recommended.