This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: c/10829: Macros that worked in 2.95.3 don't work in 3.3
- From: Zack Weinberg <zack at codesourcery dot com>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 17 May 2003 05:26:00 -0000
- Subject: Re: c/10829: Macros that worked in 2.95.3 don't work in 3.3
- Reply-to: Zack Weinberg <zack at codesourcery dot com>
The following reply was made to PR c/10829; it has been noted by GNATS.
From: Zack Weinberg <zack@codesourcery.com>
To: aaronw@net.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c/10829: Macros that worked in 2.95.3 don't work in 3.3
Date: Fri, 16 May 2003 22:25:46 -0700
aaronw@net.com writes:
> #define TEST(t, num) (PAP_ ## t ## (c->PAT_ ## t ## ( ## num ## )))
Your code is not valid: the C standard clearly states that applying ##
to two tokens whose concatenation does not form a single valid token
provokes undefined behavior. There is nothing that can be combined
with a ( or a ) to produce a single valid token, except a "placemarker"
which occurs only under exotic conditions.
A correct version of your macro would be
#define TEST(t, num) (PAP_ ## t (c->PAT_ ## t (num)))
This expands exactly the same way, but does not give the warnings.
Rule of thumb: if the things on either side of ##, after argument
substitution, are not identifiers or pp-numbers, you have made a
mistake. This is overbroad -- one may legitimately paste together
a + and an = in that order, for instance -- but covers all the normal
uses of ##.
zw