[comp.lang.c] When are macros expanded?

henry@utzoo.uucp (Henry Spencer) (02/02/90)

In article <6458@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes:
>Is the preprocessor allowed to expand macros inside #defines? If it does
>so uniformly, then ANSI's rule about recursive macros is easy to enforce
>and implement, but certain tricks aren't possible. (Maybe this is a good
>thing.) Does ANSI say anything about this? What's the ``best'' behavior?

ANSI in general has pinned down the semantics of preprocessing much more
precisely than before, although this particular question was (somewhat
vaguely) addressed even by K&R1.  Expansion of "inner" macros happens at 
invocation time, not at definition time.

Implementing the recursion rule is a pain, actually.
-- 
1972: Saturn V #15 flight-ready|     Henry Spencer at U of Toronto Zoology
1990: birds nesting in engines | uunet!attcan!utzoo!henry henry@zoo.toronto.edu