How do I specify an integer literal of type unsigned char in C++?

前端 未结 9 1645
灰色年华
灰色年华 2020-12-08 18:38

I can specify an integer literal of type unsigned long as follows:

const unsigned long example = 9UL;

How do I do likewise for an unsigned

9条回答
  •  庸人自扰
    2020-12-08 18:49

    C provides no standard way to designate an integer constant with width less that of type int.

    However, stdint.h does provide the UINT8_C() macro to do something that's pretty much as close to what you're looking for as you'll get in C.

    But most people just use either no suffix (to get an int constant) or a U suffix (to get an unsigned int constant). They work fine for char-sized values, and that's pretty much all you'll get from the stdint.h macro anyway.

提交回复
热议问题