什么是uint8_t有乘以布尔值的类型? [英] What is the type of uint8_t multiplied by boolean value?

查看:179
本文介绍了什么是uint8_t有乘以布尔值的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准,我试图了解前pression将最终哪种类型最多是:

From the standard, I was trying to understand which type the expression will end up to be:

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

我是保证 myBool 将被强制转换为 uint8_t有(又名 unsigned char型),或整个结果可能是 INT

Am I guaranteed that myBool will be casted to uint8_t (a.k.a. unsigned char), or the whole result might be int?

有用的链接:布尔为int的转换

推荐答案

5例pressions

9许多二元运算符意想不到算术或查点操作数
    化型原因转化和产量的结果类型以类似的方式。
    目的是得到一个常见的​​类型,这也是该类型
    结果。这种模式被称为正常的算术转换,
    其被定义为如下:

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:

...

- 否则,积分促销( conv.prom 的)应进行
      两个operands.1)

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

4.5积分促销活动

1类型char,有符号的字符,无符号的字符,短整型,或右边的值
    无符号的短整型可转换为int类型是否为int的右值
    可以重新present源类型的所有值;否则,源
    右值可以被转换成unsigned int类型的右值

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 bool类型的右值可以被转换成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

In your case, both the LHS and RHS will be promoted to int before the arithmetic operation and the resultant will be of type int.

这篇关于什么是uint8_t有乘以布尔值的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆