Multicharacter literal in C and C++

前端 未结 6 984
别那么骄傲
别那么骄傲 2020-11-22 03:30

I didn\'t know that C and C++ allow multicharacter literal: not \'c\' (of type int in C and char in C++), but \'tralivali\' (of type int!)

6条回答
  •  佛祖请我去吃肉
    2020-11-22 04:14

    It makes it easier to pick out values in a memory dump.

    Example:

    enum state { waiting, running, stopped };
    

    vs.

    enum state { waiting = 'wait', running = 'run.', stopped = 'stop' };
    

    a memory dump after the following statement:

    s = stopped;
    

    might look like:

    00 00 00 02 . . . .
    

    in the first case, vs:

    73 74 6F 70 s t o p
    

    using multicharacter literals. (of course whether it says 'stop' or 'pots' depends on byte ordering)

提交回复
热议问题