On 2011-06-11 14:54, Renoir wrote: > Sorry for the question but i'm an absolutely noob > I have: > > byte x = 10; > byte y = 3; > x = x + y; > > why compilers complains? > > Error: cannot implicitly convert expression (cast(int)x + cast(int) > y > ) of type int to byte > > Have i to make another cast to sum byte + byte?
All integral operations where the types are int or smaller result in an int (unless you're dealing with unsigned types, in which case, I believe that the result would be uint). So, in this case the result of x + y is int. So, if you want the result to be byte, you have to do x = cast(byte)(x + y); - Jonathan M Davis
