UMBC CMSC 201 Fall '05
CSEE | 201 | 201 F'05 | 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               */

#endif


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

Sunday, 20-Nov-2005 18:07:37 EST