zoukankan      html  css  js  c++  java
  • C语言中的警告overflow in implicit constant conversion

    程序很简单,

     1 #include<stdio.h>
     2 #define Name  "Keal"
     3 #define Address "W.DC"
     4 #define Male "Man"
     5 #define With 40
     6 #define SPACE ' '
     7 void starbar(char ch,int num);
     8 int main(void)
     9 {    starbar('*',With);
    10     putchar('
    ');
    11     
    12     starbar(SPACE,18);
    13     printf("%s
    ",Name);
    14     starbar(SPACE,18);
    15     printf("%s
    ",Address);
    16     starbar(SPACE,19);
    17     printf("%s
    ",Male);
    18     
    19     starbar('#',With);
    20     putchar('
    ');
    21     return 0;
    22 }
    23 void starbar (char ch, int num)
    24 {    int i;
    25     for(i=0;i<num;i++)
    26     {
    27         putchar(ch);
    28         
    29     }
    30 }
    简单的小函数 程序

    刚开始的时候,出现了 overflow in implicit constant conversion。

    这个错误就是:常量转换溢出。C语言中char, int, float, double,unsigned char, unsigned int 等数值有极限范围,当它们之间(隐式)转换时,可能因 数值极限 而超界 溢出。有的编译器会报告这一类型的错误,并不是所有编译器都会报告。

    后来才发现,是因为 宏定义 

    1 #define SPACE    '  '  //打了两个空格
    2 
    3 #define SPACE    ' '  //打了一个空格

     那个starbar 函数函数原型 :

    1 void starbar(char ch,int num);

    所以多打了一个就是字符串了···呜呜,当然超出 char的范围了·····以后这种 warning 还是要注意·····防患于未然,养成好习惯·····

  • 相关阅读:
    [Azure][PowerShell][ASM][03]Cloud Service
    linux ssh连接自动断开问题
    NTP服务器实现
    xshell使用小技巧
    elasticsearch集群部署
    redis集群部署
    积分排名查看
    linux centos7.2系统升级python后yum不能使用的问题
    Python生成器generator之next和send运行流程
    python文件操作
  • 原文地址:https://www.cnblogs.com/kalo1111/p/3279543.html
Copyright © 2011-2022 走看看