Date: Wed, 10 Jul 1996 22:37:58 -0700 (MST) From: Don Yuniskis <dgy@rtd.com> To: bde@zeta.org.au (Bruce Evans) Cc: dgy@rtd.com, freebsd-hackers@freefall.freebsd.org, freebsd-ports@freefall.freebsd.org Subject: Re: Q: macro expansion Message-ID: <199607110537.WAA17247@seagull.rtd.com> In-Reply-To: <199607102304.JAA31461@godzilla.zeta.org.au> from "Bruce Evans" at Jul 11, 96 09:04:05 am
next in thread | previous in thread | raw e-mail | index | archive | help
> > #define X 1
> > #define Y 2
> > X+Y
> >I was surprised to see that ``X+Y'' was expanded to ``1 +2''. So,
> >I started digging through ANSI and couldn't seem to locate something
> >to clearly define this behaviour.
> > - why the inserted whitespace?
>
> See the ISO C standard section 6.8.3 (Macro Replacement). Macros are
> expanded as if they were tokenized before expansion (so a `+' at the
Ah! Hadn't realized that! ^^^^^^^^^^^^^^^^^^^^^^
> end of X doesn't get joined with the `+' in X+ to form a `++' token).
> This is usually implemented by inserting whitespace so that tokenizing
> after expansion gives the same result.
>
> > - why no whitespace after `+'?
>
> This is a bug in gcc-2.6.3. It actually gives `` 1 +2 '', while
Thanx! The inconsistency was what had me most confused!
> the version in gcc-2.7.2 gives ``1 + 2 ''. The
> difference is important for
>
> #define Y +
> int z;
> main() { printf("%d\n", +Y z); }
>
> For gcc-2.6.3, ``+Y z'' expands to ``++ z'' so there is a bogus `++'
> token and the result is 1. For gcc-2.7.2, it expands to ``+ + z''
> and the result is 0.
>
> Anyway, don't use `gcc -E' as a general purpose macro expander.
> `gcc -E -traditional' and /usr/bin/cpp work better.
Thanx!
--don
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607110537.WAA17247>
