c++ - Warning : overflow in implicit constant conversion -


in following program, line 5 give overflow warning expected, surprisingly line 4 doesn't give warning in gcc: http://www.ideone.com/u0bxn

int main() {     int = 256;     char c1 = i;    //line 4     char c2 = 256;  //line 5     return 0; } 

i thinking both lines should give overflow warning. or there i'm missing?


the topic led me experiment this: typedef type checking?

there said following(which deleted answer, because when run it, didn't show had expected):

//however, you'll warning case:  typedef int  t1; typedef char t2;  t1 x = 256;      t2 y = x; //possible overflow warning! (but doesn't give warning :() 

-wall doesn't include many options. -wconversion 1 of them , warns behavior you're interested in.

see http://gcc.gnu.org/onlinedocs/gcc/warning-options.html


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -