C99标准学习笔记(2)——整数提升
来源:互联网 发布:得力dl33113怎样数据 编辑:程序博客网 时间:2024/06/05 05:32
C99标准学习笔记(2)——整数提升
本文的copyleft归gfree.wind@gmail.com所有,使用GPL发布,可以自由拷贝,转载。但转载请保持文档的完整性,注明原作者及原链接,严禁用于任何商业用途。
作者:gfree.wind@gmail.com
博客:blog.focus-linux.net
Usual Arithmetic Conversion: The integer promotions are performed on both operands. Then the following rules are applied to the promoted operands:
If both operands have the same type, then no further conversion is needed.
Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank is converted to the type of the operand with greater rank.
Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted the type of the operand with unsigned integer type.
Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, then the operand with unsigned integer type is converted to the type of the operand with signed integer type.
Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type.
献丑翻译成中文:
整数提升:整数提升可以应用于所有的操作数,下面是整数提升的规则:
如果两个操作数具有相同的类型,那么不需要任何的转换;
不然,如果两个操作数同为有符号整数或者同为无符号整数,则rank小的操作数需要被提升为rank大的操作数的类型;
不然,一个无符号操作数的rank大于或者等于另外一个有符号操作数,则该有符号操作数的类型会提升为无符号操作数的类型;
不然,一个有符号操作数可以表示另一个无符号数的所有的值,那么那个无符号操作数的类型需转换为该有符号类型;
不然,两个操作数都需要转换为有符号数对应的无符号类型——这种情况,我没有找出实例,哪位朋友指点一下呢。
虽然整数类型提升为C的基础概念,但是不看标准的话,我想大多数人不会特别清楚——包括我在内,即使平时因为注意这个问题,而不会因此犯错。尤其是第4条,至少我以前就不甚了解。我会认为有符号数都会转为无符号数的,不会认为无符号数也会转为有符号数的
- C99标准学习笔记(2)——整数提升
- C99标准学习笔记(2)——整数提升
- C99标准学习笔记(1)——一些名词解释
- C99标准学习笔记(4)——sizeof运算符
- C99标准学习笔记(4)——sizeof运算符
- C99标准学习笔记(3)——操作符&和[]
- c99 学习笔记
- C99标准
- C99标准
- C99标准
- C99—long long
- C++学习笔记2——标准库类型
- Tkinter 学习笔记 —— 标准属性
- C99标准更新
- c99新加标准。。。
- C99标准更新
- C99标准特性
- C99标准库函数
- 用c语言动态操作sqilite3数据库
- Linux tail 命令详解
- dhtmlxgrid实现左右列表数据移动
- A标签切换图片
- Winsock异步----select模型的前前后后
- C99标准学习笔记(2)——整数提升
- 统计自然语言处理基础学习笔记(1)
- Android 滑动效果入门篇(二)—— Gallery
- SQLITE3 使用总结
- 编写安全代码:再论整数类型转换 (
- FileUtils
- 记录Objective-C里SEL和Selector的用法
- 整理:分页存储过程整理
- Java String类的split方法使用