Macro Substitution too Complex?

Karl Heuer karl at haddock.ima.isc.com
Sun May 6 13:17:49 AEST 1990


In article <1990May5.014816.26452 at agate.berkeley.edu> c60c-2ca at WEB.berkeley.edu (Andrew Choi) writes:
>Hi everyone.  I thought I understood how macro substituion
>works, until I came up with the following example: ...

Since the example uses the `##' operator, we're talking about ANSI C here.

>One possible explanation is that macro substitution is not recursive.

You got it.  It's normally pretty useless for macro substitution to be done
recursively, since there's no way for it to bottom out (the preprocessor
sublanguage lacks a conditional that can be executed within a macro), so it
was decreed to be nonrecursive (so one can write `#define char signed char',
for example).

>However, is this a standard behavior?

Yes, this sort of behavior is required for a conforming implementation.

>Does anyone know the "standard" rules for performing macro substitution?

I would guess that very few people know them completely; I'm not one of them.
There are some rather subtle issues involved; see the examples in the ANS.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list