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.
 
I extract out some fragments  of C99 standard to explain the integer promotions are performed on both operands.
 example:
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #define PRINT_COMPARE_RESULT(a, b) \
  4. if (a > b) { \
  5. printf( #a " > " #b "\n"); \
  6. } \
  7. else if (a < b) { \
  8. printf( #a " < " #b "\n"); \
  9. } \
  10. else { \
  11. printf( #a " = " #b "\n" ); \
  12. }
  13.  
  14. int main()
  15. {
  16. int a = -;
  17. unsigned short b = ;
  18. unsigned int c = ;
  19.  
  20. PRINT_COMPARE_RESULT(a,b);
  21. PRINT_COMPARE_RESULT(a,c);
  22.  
  23. return ;
  24. }

The result is a > c and a < b.

Operands a that has signed integer type has rank less than the rank of the type of the operand c,so the a with signed integer type is converted the type of the c with unsigned integer type.The signed integer -1 is coverted to unsigned integer is 0xffffffff that is greater than the value 3 of unsigned integer c.However, the rank of a is greater than the rank of b that has unsigned short integer type,so the unsigned short integer type is converted to signed int type.So a < b.

 
 

The integer promotion.的更多相关文章

  1. 【C】 03 - 数据类型

    程序说到底就是对数据的处理,所以首先要弄清楚需要处理哪些数据,计算机如何存储这些数据.C语言根据需要,抽象出了一些基本数据类型和衍生数据类型.这些可以满足大部分需求,更复杂的抽象数据类型亦可通过它们来 ...

  2. 消除第三方库moodycamel的编译器警告

    在项目中需要引入第三方无锁队列,此处我选用的是moodycamel. 然而引入头文件编译之后,一直提示报错信息,需要专门针对此文件消除编译警告(本人使用GCC编译器). 在文件头处添加如下语句: #i ...

  3. C-类型转换(陷阱)

    getchar() 返回值为int类型 1.自动类型转换(运算符两边变量类型不同时) 1).两个变量类型自动转换成一样的类型(会根据参数类型自动转换, 而不是直接位转换), 且运算结果也是转换后的类型 ...

  4. C/C++ 中的算术及其陷阱

    目录 概述 C/C++ 整数的阴暗角落 整型字面量 整型提升与寻常算术转换 算术溢出检测 位运算技巧 总结 参考 概述 无符号数和有符号数是通用的计算机概念,具体到编程语言上则各有各的不同,程序员是解 ...

  5. [Linux] Linux C编程一站式学习 Part.2

    C语言本质 计算机中数的表示 浮点数:符号位+指数部分(2的多少次方)+尾数部分(小数点后的数字) 用偏移的指数(Biased Exponent)表示负指数 正规化(Normalize):尾数部分最高 ...

  6. char、signed char、unsigned char的区别总结。

    转载地址:http://hi.baidu.com/thewillreigns/blog/item/67e665c4296e69c038db492d.html char 和 unsigned char是 ...

  7. 洛谷P3605 [USACO17JAN] Promotion Counting 晋升者计数 [线段树合并]

    题目传送门 Promotion Counting 题目描述 The cows have once again tried to form a startup company, failing to r ...

  8. [BZOJ4756][Usaco2017 Jan]Promotion Counting 树状数组

    4756: [Usaco2017 Jan]Promotion Counting Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 305  Solved: ...

  9. LeetCode 7. Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you ...

随机推荐

  1. TIJ——Chapter Seven:Reusing Classes

    Reusing Classes 有两种常用方式实现类的重用,组件(在新类中创建存在类的对象)和继承. Composition syntax Every non-primitive object has ...

  2. Unity和Android互相调用

    安卓部分代码: public class GameMainActivity extends UnityPlayerActivity { private static String CODE_ROOT ...

  3. Url通配符映射

    原文:http://www.cnblogs.com/liukemng/p/3726897.ht 1.URL路径映射 1.1.对一个action配置多个URL映射: 我们把上一篇中的HelloWorld ...

  4. nyist 78 圈水池

    http://acm.nyist.net/JudgeOnline/problem.php?pid=78 圈水池 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 有一个 ...

  5. js 控制浏览器窗口大小

    //打开一个新窗口并设置其大小window.open('index.html','','width=450,height=750,location=no,menubar=no,status=no,to ...

  6. PHP扩展开发及内核应用

    目录中汉字部分代表已经翻译完成的章节,带链接的表示已经发布的,未待链接的表示正在校正即将发布的. PHP的生命周期 让我们从SAPI开始 PHP的启动与终止 PHP的生命周期 线程安全 小结 PHP变 ...

  7. ubuntu command

    uninstall software: sudo apt-get purge openjdk*

  8. iOS开发:http中的get和post请求

    什么是 HTTP ? 超文本传输协议(HTTP)的设计目的是保证客户端与服务器之间的通信. HTTP 的工作方式是客户端与服务器之间的请求-应答协议. web 浏览器可能是客户端,而计算机上的网络应用 ...

  9. js基础练习一之tab选项卡

    最近在学习前端,当然包括js,css,html什么的,在听课时做的一些小练习,记录下来: 实例一: --Tab选项卡-- <script type="text/javascript&q ...

  10. SVN提交时响应很慢,我是这样解决的。

    现象:使用TortoiseSVN提交文件时,弹出提交窗口,要等待30秒的样子,才开始工作,开始提交文件后速度还是很快的. 解决后提交文件几乎是秒杀. 解决办法 (我的电脑可以了,但还是有些同事的电脑没 ...