Multicharacter literal in C and C++

前端 未结 6 860
别那么骄傲
别那么骄傲 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:24

    Four character literals, I've seen and used. They map to 4 bytes = one 32 bit word. It's very useful for debugging purposes as said above. They can be used in a switch/case statement with ints, which is nice.

    This (4 Chars) is pretty standard (ie supported by GCC and VC++ at least), although results (actual values compiled) may vary from one implementation to another.

    But over 4 chars? I wouldn't use.

    UPDATE: From the C4 page: "For our simple actions, we'll just provide an enumeration of some values, which is done in C4 by specifying four-character constants". So they are using 4 chars literals, as was my case.

提交回复
热议问题