say I have the following
#define STR(x) #x
#define ONE 1
#define TWO 2
typedef struct
{
int item;
char * name;
}bag_t;
bag_t my_bag[] =
{
{ONE, ""};
{TWO, ""};
}
I want to add the name of the macro to the name variable so something like this:
my_bag[1].name = STR(my_bag[1].item);
That obviously doesn't work since it not expanded. How can workaround this?
Not sure if this is 100% what you want, but perhaps it's close enough:
This prints: