ABSTRACT

This chapter discusses how to define and use macros in a C program. It describes preprocessor directives and operators. The behavior of the preprocessor is controlled by directives. The directives are special commands that begin with a # character and instruct the preprocessor to do something. Directives can appear anywhere in the program. Besides its simple form, a macro can take parameters and behave like a function. The # operator in front of an argument instructs the preprocessor to create a string literal having the name of that argument. The preprocessor directives allow the conditional compilation of a part of the program. The conditional compilation can be very useful in many situations, for example, to debug the program, to monitor the program execution, or to maintain multiple versions of the same program. The #if and #endif directives are used to define which parts of a program will be compiled, depending on the value of an expression.