Macro -> How to remove redundant code

M

MaciekL

Hi,

I have to write a macro TEST:

...................
#define M(x) a.x,
#define TEST(a, b) b 0
TEST(bar, M(foo) M(ptr))
...................
result:
a.foo, a.ptr, 0
...................

Question: How to implement macro,
that produces following result:
bar.foo, bar.ptr, 0

I know the following soultion is working correctly,
but it contains redundant information:
...................
#define M(a, x) a.x,
#define TEST(b) b 0
TEST(M(bar, foo) M(bar, ptr))
...................

Regards
 
K

Keith Thompson

MaciekL said:
I have to write a macro TEST:

..................
#define M(x) a.x,
#define TEST(a, b) b 0
TEST(bar, M(foo) M(ptr))
..................
result:
a.foo, a.ptr, 0
..................

Question: How to implement macro,
that produces following result:
bar.foo, bar.ptr, 0

I know the following soultion is working correctly,
but it contains redundant information:
..................
#define M(a, x) a.x,
#define TEST(b) b 0
TEST(M(bar, foo) M(bar, ptr))
..................

Why exactly do you "have to" do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top