c – uint8_t的类型乘以布尔值是什么?

c – uint8_t的类型乘以布尔值是什么?,第1张

概述从 standard开始,我试图了解表达式最终会是哪种类型: bool myBool;[...]uint8_t(255) * (myBool); 我保证myBool会被转换为uint8_t(a.k.a.unsigned char),或者整个结果可能是int吗? 有用链接:bool to int conversion 从您链接到的文档: 5 Expressions 9 Many binary o 从 standard开始,我试图了解表达式最终会是哪种类型:

bool myBool;[...]uint8_t(255) * (myBool);

我保证myBool会被转换为uint8_t(a.k.a.unsigned char),或者整个结果可能是int吗?

有用链接:bool to int conversion

解决方法 从您链接到的文档:

5 Expressions

9 Many binary operators that expect operands of arithmetic or enumera-
tion type cause conversions and yIEld result types in a similar way.
The purpose is to yIEld a common type,which is also the type of the
result. This pattern is called the usual arithmetic conversions,
which are defined as follows:

–Otherwise,the integral promotions (conv.prom) shall be performed
on both operands.1)

4.5 Integral promotions

1 An rvalue of type char,signed char,unsigned char,short int,or
unsigned short int can be converted to an rvalue of type int if int
can represent all the values of the source type; otherwise,the source
rvalue can be converted to an rvalue of type unsigned int

4 An rvalue of type bool can be converted to an rvalue of type int,with
false becoming zero and true becoming one.

在您的情况下,LHS和RHS都将在算术运算之前被提升为int,结果将是int类型.

总结

以上是内存溢出为你收集整理的c – uint8_t的类型乘以布尔值是什么?全部内容,希望文章能够帮你解决c – uint8_t的类型乘以布尔值是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1216261.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存