On Nov 2, 12:19*am, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> marv andersen <marv...@googlemail.com> writes:
> > What should the following produce after preprocessing
> > #define y(x) x
> > #define x(a) y(a
> > x(1) x(2)))
>
> > I think we should get '1 2', but cpp on linux seems to think this
> > expands to an invalid use of y? *My reasoning is that we should get
> > the following:
> > y(1 x(2)))
> > y(1 y(2))
> > y(1 2)
> > 1 2
>
> > ... but maybe I'm missing something.
>
> cpp is correct. *The key wording from the standard is this (from
> 6.10.3.1 para 1):
>
> * "Before being substituted, each argument’s preprocessing tokens are
> * completely macro replaced as if they formed the rest of the
> * preprocessing file; no other preprocessing tokens are available."
>
> Is that enough? *Because this looks like coursework, I am inclined to
> leave it at that, but if you are still puzzled, say so, and I'll include
> a fuller explanation.
>
> --
> Ben.
Thanks - I see my mistake, the extra )s aren't visible when the
argument '1 x(2)' is being expanded, as we're 'argument expanding',
not 'rescanning' at this point, so we get as far as '1 y(2' but then
find we're missing the closing ). [Not coursework BTW, just trying to
understand cpp a bit better.]
|