DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Complying with standard C

Macro replacement

The macro replacement process has never been described in any significant detail prior to ANSI C. This vagueness spawned a great many divergent implementations and any code that relied on anything fancier than manifest constant replacement and simple ?:-like macros was probably not truly portable. This tutorial cannot begin to uncover all the subtle and not so subtle differences between the old C macro replacement implementation and the ANSI C version. Fortunately, nearly all uses of macro replacement with the exception of token pasting and stringizing will produce exactly the same series of tokens as before. Furthermore, the ANSI C macro replacement algorithm can do things not possible in the old C version. For example:

   #define name   (*name)
causes any use of name to be replaced with an indirect reference through name. (The old C preprocessor would produce a large amount of parentheses and stars and eventually complain about macro recursion.)

The major change in the macro replacement approach taken by ANSI C is to require macro arguments (other than those that are operands of the macro substitution operators # and ## ) to be expanded recursively prior to their substitution in the replacement token list. However, this change seldom produces an actual difference in the resulting tokens.


Next topic: Stringizing
Previous topic: Logical source lines

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003