Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

Guarding Header Files

The C Preprocessor

Preprocessor Directives Used for Guarding a Header File

In our fraction.h example, notice that the file was guarded. The two preprocesssor directives (#ifndef & #define) occur near the beginning of the file and the preprocessor directive, #endif, occurs at the end of the file.

#ifndef _fraction_h     /* if fraction.h hasn't already been defined */
#define _fraction_h     /* then define it as the following ...       */
                        /* everything between the #define and the 
                           #endif will be considered _fraction_h  The  
<code of the               underscore which replaces the dot, is 
 header file>              necessary since the preprocessor can't
                           handle dots well.  The underscore before 
                           the filename is traditional               */


CSEE | 201 | 201 F'06 | lectures | news | help

Tuesday, 22-Aug-2006 07:14:12 EDT