e69 Cascaded Use of Macros Contents|Index|Previous|Next
 

Cascaded use of macros 

A cascade of macros is when one macro’s body contains a reference to another macro. This is very common practice, as in the following example.

This is not at all the same as defining TABLESIZE to be 1020. The #define for TABLESIZE uses exactly the body you specify—in this case, BUFSIZE —and does not check to see whether it too is the name of a macro.

It’s only when you use TABLESIZE that the result of its expansion is checked for more macro names. This makes a difference if you change the definition of BUFSIZE at some point in the source file. TABLESIZE, defined as in the following example, will always expand using the definition of BUFSIZE that is currently in effect.

Now TABLESIZE expands (in two stages) to 37. (The #undef is to prevent any warning about the nontrivial redefinition of BUFSIZE.) 0