Reputation: 3365
case MAP_KEY3:
case MAP_KEY4:
case MAP_KEY5:
case MAP_KEY6:
break;
default:
LampShow(LampID, 0);
LampShow(LampID, 2);
LampShow(LampID, 0);
break;
I want to make a MARCO of above code so that I can use it anywhere repeatedly. But how to do? It is for C language.
If I do it like below:
#define AAA /
case MAP_KEY3: /
case MAP_KEY4: /
case MAP_KEY5: /
case MAP_KEY6: /
break; /
default: /
LampShow(LampID, 0); /
LampShow(LampID, 2); /
LampShow(LampID, 0); /
break;
Then I will got this error:
34: syntax error before `case'
line 34 is case MAP_KEY3: /
Upvotes: 0
Views: 125
Reputation: 41022
#define EVIL_MACRO \
case MAP_KEY3: \
case MAP_KEY4: \
case MAP_KEY5: \
case MAP_KEY6: \
break; \
default: \
LampShow(LampID, 0); \
LampShow(LampID, 2); \
LampShow(LampID, 0); \
break;
Upvotes: 5
Reputation:
I want to make a MARCO of above code so that I can use it anywhere repeatedly
That's what functions are for.
Upvotes: 3