# Macro that Defines another on invocation

A

#### aravindh.k

Hi,

I want to define a macro that defines another on invocation. Somthing
like this:

#define MACRO_NR_1(FLAG, VALUE) #define MACRO_NR_1_##FLAG(VALUE)
(VALUE+FLAG)

So that when I call MACRO_NR_1(10), the macro MACRO_NR_1_10 gets
defined. The macro above does not work.

Do you know how I may do this ?

Sincerely,
Aravindh

P

#### Pieter Droogendijk

Hi,

I want to define a macro that defines another on invocation. Somthing
like this:

#define MACRO_NR_1(FLAG, VALUE) #define MACRO_NR_1_##FLAG(VALUE)
(VALUE+FLAG)

# is, in fact, a pre-processor operator. It's operand should be one of the
function-like macro's parameters, the 'value' of which will then be
magically transformed into a string literal.

So this is definitely not going to work.
So that when I call MACRO_NR_1(10), the macro MACRO_NR_1_10 gets
defined. The macro above does not work.

Do you know how I may do this ?

You may not.

6.10.3.4 #3: "The resulting completely macro-replaced preprocessing token
sequence is not processed as a preprocessing directive even if it
resembles one."

The "resulting completely macro-replaced preprocessing token sequence"
being your fully processed macro replacement.