zoukankan      html  css  js  c++  java
  • subtle bug 一个非常细微的bug

    int arrary[]={23,34,12,17,204,99,16};
    #define TOTAL_ELEMENTS (sizeof(array))/sizeof(arrary[0])
    main()
    {
    int d=-1,x;
    if(d<=TOTAL_ELEMENTS-2)
    {
    x
    =arrary[d+1]
    }
    }

    sizeof的返回类型是unsigned int。if语句中的,d由int类型被提升为unsigned int。结果-1变成正数255。if就不能被执行了。

    总之,朝表示范围大的方向扩展:

    First, if either operand is long double, the other is converted to long double.
    Otherwise, if either operand is double, the other is converted to double.
    Otherwise, if either operand is float, the other is converted to float.
    Otherwise, the integral promotions are performed on both operands; then, if either operand is unsigned long int, the other is converted to unsigned long int.
    Otherwise, if one operand is long int and the other is unsigned int, the effect depends on whether a long int can represent all values of an unsigned int; if so, the unsigned int operand is converted to long int; if not, both are converted to unsigned long int.
    Otherwise, if one operand is long int, the other is converted to long int.
    Otherwise, if either operand is unsigned int, the other is converted to unsigned int.
    Otherwise, both operands have type int.
     

  • 相关阅读:
    我的第一篇博客
    汇编语言——基础知识 Cop
    汇编语言第二章实验 Cop
    什么是<!DOCTYPE html>
    python第三方模块安装的几个方式
    linux下安装memcacheQ
    python正则表达式
    边框背景
    伪类
    属性选择符和样式
  • 原文地址:https://www.cnblogs.com/smartvessel/p/2026460.html
Copyright © 2011-2022 走看看