加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 错误:隐式常量转换溢出[-Werror = overflow]

发布时间:2020-12-16 09:44:57 所属栏目:百科 来源:网络整理
导读:错误:隐式常量转换溢出[-Werror = overflow] #includestdio.hint main(){ char ch=200; printf("n%d",ch); return 0;} 我在http://ideone.com/YNkKT6#view_edit_box上运行此代码并获得隐式转换错误. 我需要进行哪些修改以及原因是什么? 解决方法 n3376 3.
错误:隐式常量转换溢出[-Werror = overflow]

#include<stdio.h>

int main()
{ 
    char ch=200;
    printf("n%d",ch);
    return 0;
}

我在http://ideone.com/YNkKT6#view_edit_box上运行此代码并获得隐式转换错误.
我需要进行哪些修改以及原因是什么?

解决方法

n3376 3.9.1 / 1

Plain char,signed char,and unsigned char are three distinct types. A char,a signed char,and an
unsigned char occupy the same amount of storage and have the same alignment requirements (3.11); that is,
they have the same object representation.

什么是char是实现定义的,所以,你需要unsigned char来处理值(0-255).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读