By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,426 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,426 IT Pros & Developers. It's quick & easy.

Macro that Defines another on invocation

P: n/a
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

Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 22 Nov 2005 03:25:38 -0800, aravindh.k wrote:
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.

--
Pieter Droogendijk <pi****@binky.org.uk>
PGP/1E92DBBC [ Make way for the Emperor's Finest. ] binky.org.uk

Nov 23 '05 #2

P: n/a
dank u.

I will not try it again. I plan to use inline functions now.
Thanks for pasting the standard, now I know it cannot be done in ANSI C.

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.