简体   繁体   中英

How to define it as a 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;

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: /

#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;

I want to make a MARCO of above code so that I can use it anywhere repeatedly

That's what functions are for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM