Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: overflow in implicit constant conversion [-Werror=overflow]

Tags:

c++

c

error: overflow in implicit constant conversion [-Werror=overflow]

#include<stdio.h>

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

I am running this code on http://ideone.com/YNkKT6#view_edit_box and getting the implicit conversion error. What modification do I need and what is the reason?

like image 492
sv1 Avatar asked Sep 01 '25 17:09

sv1


1 Answers

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.

What is char is implementation-defined, so, you need unsigned char here, that handles values (0-255).

like image 157
ForEveR Avatar answered Sep 04 '25 07:09

ForEveR