HP C/iX Reference Manual (31506-90011)
Chapter 7 105
Preprocessing Directives
Macro Replacement
operators that might be used with the MAX macro.
Using a macro definition for MAX has some advantages over a function definition. First, it
executes faster because the macro generates in-line code, avoiding the overhead of a
function call. Second, the MAX macro accepts any argument types. A functional
implementation of MAX would be restricted to the types defined for the function. Note
further that because each argument to the MAX macro appears in the token string more
than once, check to be sure that the actual arguments to the MAX macro do not have any
"side effects." The following example
MAX(a, b);
might not work as expected because the argument a is incremented two times when a is
the maximum.
The following statement
i = MAX(a, b+2);
is expanded to:
i = ((a) > (b+2) ? (a) : (b+2));
Examples
#define isodd(n) ( ((n % 2) == 1) ? (TRUE) : (FALSE))
/* This macro tests a number and returns TRUE if the number is odd. It will
*/
/* return FALSE otherwise.
*/
#define eatspace() while( (c=getc(input)) ==''||c=='\n' || c == '\t' )
;
/* This macro skips white spaces.
*/