#include <foobar.h>
#define ADD(a,b) (a+b)and is used like this:
x = ADD(y,5) * 7;[Do you see why the paranthesis around a+b in the macro definition is a good idea?] Just like #define constants, #define macros get expanded textually before compilation.
(boolean-expression) ? (expression-1) : (expression-2)If the boolean-expression is true, then the result of the entire thing is expression-1. Otherwise, it is expression-2. The single two most popular uses of this are
#define MAX(a,b) ( a > b ? a : b ) #define MIN(a,b) ( a < b ? a : b )
#if defined(DEBUG) printf( "x = %d\n", x ); #endifthen the printf statement is included in the file at compile time only if there is a preprocessor macro called DEBUG defined at that point. You often see, for example, the lines
#if defined(FOOBAR.H) #define FOOBAR.H ... #endifsurrounding the rest of the file foobar.h. This prevents bad things from happening if foobar.h is included more than once in another program (which can easily happen if you include both stuff1.h and stuff2.h, say, and stuff2.h includes stuff1.h.)
#if defined(DEBUG) || defined(VERBOSE)or
#if !defined(MAC) && defined(MSDOS)
gcc foobar.c -c -DDEBUG -DFALSE=0