char 型数据本质上是没有算术和逻辑运算的

------------------------------------------------------------------------------------------------------------------------------

"A character, a short integer, or an integer bit-field, all either signed or not,  or an object of enumeration type, may be used in an expression wherever an integer maybe used.  If an int can represent all the values of the original type, then the value is converted to int; otherwise the value is converted to unsigned int. This process is called integral promotion."  

------------------------------------------------------------------------------------------------------------------------------------------------

(戳)MISRA C:  Motor Industry Software Reliability Association


整数提升(Integral promotion)转换
整数提升描述了一个过程,借此过程数值操作总是在int 或long(signed 或unsigned)整型操作数上进行。其他整型操作数(char、short、bit-field 和enum)在数值操作前总是先转化为int 或unsigned int 类型。这些类型称为small integer 类型。整数提升的规则命令,在大多数数值操作中,如果 int 类型能够代表原来类型的所有值,那么small integer 类型的操作数要被转化为int 类型;否则就被转化为unsigned int。

注意,整数提升
- 仅仅应用在 small integer 类型上
- 应用在一元、二元和三元操作数上
- 不能用在逻辑操作符(&&、||、!)的操作数上
- 用在 switch 语句的控制表达式上

[规则 6.1]  :  单纯的 char 类型应该只用做存储和使用字符值。
[规则 6.2]  :  signed char 和 unsigned char 类型应该只用做存储和使用数字值。
[规则10.5] :  如果位运算符 ~ 和 << 应用在基本类型为unsigned char 或unsigned short 的操作数,结果应该立即强                       制转换为操作数的基本类型。
====================================================================================  更多参考文档(戳) MISRA C:2004 
====================================================================================

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值