[comp.lang.c] Proposed ANSI C Preprocessor is inconsistent!

rcvie@tuvie (ELIN Forsch.z.) (12/21/87)

I am trying to implement a preprocessor that is already capable of the
forthcoming ANS. (My reference for it is the ISO Draft, however, I do
not know of any differences or changes between these standards concerning
the preprocessor.) As you know there have been some useful features added
to the macro processor, but the standard is not free of inconsistencies
in this point. I will explain it using some examples that the standard uses
itself.

Example:
#define x	3
#define f(a)	f(x * (a))
#undef  x
#define x	2
#define g	f
#define z	z[0]
#define h	g(~
#define m(a)	a(w)
#define w	0,1
#define t(a)	a

f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
	...

Let's take the part "f(f(z))"

f(f(z))
First we expand the argument:
  f(z)
  First we expand the argument:
    z -> z[0]
    No further expansions
  f(z) -> f(x * (z[0]))
  Rescanning:
  f(z) -> f(2 * (z[0][0]))
  No further expansions
f(f(z)) -> f(x * (f(2 * (z[0][0]))))
Rescanning:
f(f(z)) -> f(2 * (f(2 * (z[0][0][0]))))
No further expansions

OOPS: The standard's result is f(2 * (f(2 * (z[0])))) !!!!
Asumption: inserted arguments are not rescanned any more (which leads to
the proposed result).

If we, however, expand the part "t(t(g)(0) + t)(1)":

t(t(g)(0) + t)(1)
First we expand the argument:
  t(g)(0) + t
  First we expand the argument
    g -> f
    No further expansions (as no argument parenthesis follows "f")
  t(g)(0) + t -> f(0) + t	("t" cannot be expanded, as no argument
                                 parenthesis follows)
  Rescanning:
  f(0) + t -> f(2 * (0)) + t	("f" is expanded in the standard, although
                                 it was the result of an inserted argument!!!!)
  No further expansions
t(t(g)(0) + t)(1) -> f(2 * (0)) + t(1)
No further expansions	("t" is currently expanding, so it is not expanded
                         any more)

In this example rescanning of inserted arguments is handled in two different
ways. Does anybody know, what went wrong here? What may be deduced from
the intentions of the committee? Any suggestions? Corrections?


			Dipl.Ing. Dietmar Weickert
			ALCATEL Austria - ELIN Research Center
			Floridusg. 50
			A-1210 Vienna/Austria/Europe