What I meant was ... suppose you have three "names" (foo, bar, and squid) ... that means you want the following code to appear after all macro expansions:
-
-
Foo foo;
-
Bar bar;
-
Squid squid;
-
...
-
(Foo *) (foo->myMember.anum) = fooVal;
-
(Bar *) (bar->myMember.anum) = barVal;
-
(Squid *) (squid->myMember.anum) = squidVal;
-
My suggestion is to get the equivalent through the following ...
-
-
typedef Foo *ptr_foo;
-
typedef Bar *ptr_bar;
-
typedef Squid *ptr_squid;
-
...
-
#define mac(name, val) (ptr_ ## name)(name->myMember.anum) = val
-
...
-
Foo foo;
-
Bar bar;
-
Squid squid;
-
...
-
mac(foo, fooVal);
-
mac(bar, barVal);
-
mac(squid, squidVal);
-
These macros expand into the three lines:
-
-
(ptr_foo)(foo->myMember.anum) = fooVal;
-
(ptr_bar)(bar->myMember.anum) = barVal;
-
(ptr_squid)(squid->myMember.anum) = squidVal;
-
Which, because of the typedefs, is equivalent to what you want.
I haven't tried this out on a compiler, so there might be syntax issues for you to work out, but I'm pretty sure the concept is valid.