UWA Logo Computer Science & Software Engineering
C Programming (CITS1210) - Lecture 5
 
    CITS1210  |  help1210

File inclusion using the C preprocessor

To date, we've used the C-preprocessor to include a number of the standard header files that are part of ISO-C99, with the syntax:


#include  <stdio.h>
#include  <stdlib.h>

What is really happening here? Each installation of a C compiler on an operating system will come with the 18 standard header files. On our Macs, Linux, and Unix systems, these header files are stored in the directory:

    /usr/include/
and, thus, the file included is /usr/include/stdio.h

A search of the /usr/include/ directory (using the ls program), will reveal many non-standard header files there, too, and further operating system-specific subdirectories and their header files.

Creating our own header files

It's also possible to create our own, non-standard, header files (we'll see this in Lecture 7).
We include our own header files with:


#include  "myheader.h"

which does not prepend any special directory name.

Note: it's normally considered very bad practice to use the C-preprocessor to include C source-code files (name.c).
We should endeavour to only include header files (myheader.h).


C Programming (CITS1210), Lecture 5, p1, 28th August 2008.