Skip to contentSkip to conversation

Macro exercise

DISCUSSION Marius Cosma 1 participant 2 messages Aug 18, 2006

lore
Share & tools
lore
#0 lore raw

Hello,

I want to use a macro for a structure member, something like:

typedef struct {
int a;
int b;
int c;
} myStruct;

myStruct x;

x.a = 7;
x.b = 8;
x.c = 9;

#undef PARAM
#define PARAM a
printf("x=%d\n", x.##PARAM);

#undef PARAM
#define PARAM b
printf("x=%d\n", x.##PARAM);

#undef PARAM
#define PARAM c
printf("x=%d\n", x.##PARAM);

But I'm having problems in writing it correct (that "x.##PARAM"). Are you faster than a google search? :)

Thanks

This email is subject to Computaris email terms of use: http://www.computaris.com/email_terms.html

#1 lore raw

Solved ... x.PARAM works just fine

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Marius Cosma
Sent: 18 August 2006 12:12
To: [email protected]
Subject: RE: Macro exercise

Hello,

I want to use a macro for a structure member, something like:

typedef struct {
int a;
int b;
int c;
} myStruct;

myStruct x;

x.a = 7;
x.b = 8;
x.c = 9;

#undef PARAM
#define PARAM a
printf("x=%d\n", x.##PARAM);

#undef PARAM
#define PARAM b
printf("x=%d\n", x.##PARAM);

#undef PARAM
#define PARAM c
printf("x=%d\n", x.##PARAM);

But I'm having problems in writing it correct (that "x.##PARAM"). Are you faster than a google search? :)

Thanks

This email is subject to Computaris email terms of use:
http://www.computaris.com/email_terms.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

This email is subject to Computaris email terms of use: http://www.computaris.com/email_terms.html