我正在使用 xc8 编译器,并想告诉他我的文字只有 8 位宽。
123
:无后缀,默认int(xc8中为16位)
123U
:unsigned int 也是 16 位宽
有一个干净的解决方案来描述 8 位文字吗?
最佳答案
Any idea for a clean solution to describe a 8 bit literal?
C 只有 2 个文字:字符串文字和复合文字 (C99)。 C 将 123
和 123u
识别为整数常量,而不是文字。
要形成 C 8 位文字:创建一个复合文字
#define OneTwoThree ((uint8_t) { 123 })
printf("%zu %x\n", sizeof(OneTwoThree), OneTwoThree);
// expected output
1 123
如果 xc8 支持复合文字,我不知道。
关于c - 8 位值有文字后缀吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50618966/