how can we use the changeable variable as a switch case label. in other words, I have a macro defined. But I need to change this value at run time depending on a condition. How can I implement this?
example is given below,
Here , case "FOO" will work?
#define CONDITION (strcmp(str, "hello") == 0)
#define FOO1 (10)
#define FOO2 (20)
#define FOO ((CONDITION) ? (FOO1) : (FOO2))
char *var="hello";
int main()
{
int p = 20;
switch(p) {
case FOO:
printf("\n case FOO");
break;
case 30:
printf("\n case 30");
break;
default:
printf("\n case default");
break;
}
return(0);
}