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.
     

  • 相关阅读:
    软件工程课程建议
    结对编程2
    结对编程---《四则运算》
    AVAudioPlayer播放音乐
    《问吧》需求分析
    有关结对编程的感想
    UItabBarController
    ViewController 视图控制器的常用方法
    <问吧>调查问卷心得体会
    UINavigationController导航控制器
  • 原文地址:https://www.cnblogs.com/smartvessel/p/2026460.html
Copyright © 2011-2022 走看看