This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A small (preprocessor) problem, and a modest enhancement proposal


"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]