next up previous contents index
Next: Mathematical functions Up: Programming in C Previous: Miscellaneous   Contents   Index


Preprocessor directives

One of C's most useful features is its preprocessor. This is a part of compilation which occurs before the main compilation, and performs simple tasks such as including header files. We will only describe two of its features.


#include

The #include preprocessor command inserts a specified file into the file being compiled. It is often used to include header files containing many function declarations:

  
#include <catam.h> /* access the CCATSL library */
this in turn contains

  
#include <stdio.h>
which declares the standard IO functions (such as printf).


#define

The simplest use of the #define pre-processor command looks like:

  
#define MAX_ITERS 1000
/* .. */
int i;
/* .. */
for (i=1; i<=MAX_ITERS; i++) { 
  /* .. */
}
This asks the preprocessor to replace occurrences of the word MAX_ITERS with 1000 (this is a common way to define constants in C). #define can also be used to define macros which behave like functions, but we will not discuss these.


next up previous contents index
Next: Mathematical functions Up: Programming in C Previous: Miscellaneous   Contents   Index
CATAM admin 2010-02-23