Given the following struct,
typedef struct tCard {
CardClass class;
void *proto;
} Card;
typedef struct tCardPath {
PathType path_type;
struct tPath path;
Goal goal;
} CardPath;
Is it possible to access the element pointed by a pointer to struct (proto) using macros, like this?
((CardPath*)(trial[i].proto))->element1; // this works
CARD_PROP(trial[i], Path, element1); // the goal
I tried this, but this gives error: expected identifier before ‘(’ token when compiling,
#define PROTO(C) (C).proto
#define CARD_PROP(C, CARD, PROP) (((Card##CARD *)(PROTO(C)))->(PROP))
EDIT: Tried this, still doesn't work
#define CARD_PROP(C, CARD, PROP) ((Card##CARD *)(PROTO(C))->PROP
((CardPath *)((trial[i]).proto)->element1;. Notice the 4 ( and the 3 )