1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Macros With Parameters


#define MacroName(parameters) macro_body


No blanks within the MacroName(parameters)


When the macro name is used in the program text a value
for each parameter must be supplied:
because this is a pure text replacement there is no
checking of types, only that there is the correct
number of parameters


When the macro body is expanded each parameter is
replaced by its value


For example:


#definecube(x)(x)*(x)*(x)


This macro will cube whatever expression is provided for x,
this is why the parenthesis are required


cube(a+b)will be expanded to


(a+b)*(a+b)*(a+b)


Without the parenthesis in the macro body, cube(a+b)will
be expanded to


a+b*a+b*a+b

March 3, 1998

Page 2

C201/TAM