This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: A small (preprocessor) problem, and a modest enhancement proposal
- From: Ian Lance Taylor <iant at google dot com>
- To: "Ronald F. Guilmette" <rfg at tristatelogic dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 01 Jul 2009 12:07:19 -0700
- Subject: Re: A small (preprocessor) problem, and a modest enhancement proposal
- References: <28786.1246422523@tristatelogic.com>
"Ronald F. Guilmette" <rfg@tristatelogic.com> writes:
> I'd like to propose a small enhancement for the GNU preprocessor, i.e.
> the addition of a new __MACRO__ pre-defined built-in symbol.
We support the __COUNTER__ macro these days. To get __COUNTER__ to be
expaned as you wish, you have to pass it through another macro
expansion. So, for example, something like the following should work.
#define APP(a, b) a ## b
#define VARNAME(a, b) APP(a, b)
#define foo1(ARG1,ARG2,V1,V2) \
{ \
register int V1 = ARG1; \
register int V2 = ARG2; \
foobar = V1 + V2; \
}
#define foo(ARG1,ARG2) \
foo1(ARG1, ARG2, VARNAME(macro_arg1_, __COUNTER__), \
VARNAME(macro_arg2_, __COUNTER__))
#define bar1(ARG1,ARG2,V1,V2) \
{ \
register int V1 = ARG1; \
register int V2 = ARG2; \
foo (V1, V2); \
}
#define bar(ARG1,ARG2) \
bar1(ARG1, ARG2, VARNAME(macro_arg1_, __COUNTER__), \
VARNAME(macro_arg2_, __COUNTER__))
Ian