byte & byte

Jesse Phillips jessekphillips+D at
Fri Oct 29 08:48:18 PDT 2010

Ellery Newcomer Wrote:

> erm, wut?
> On 10/28/2010 12:56 PM, Jesse Phillips wrote:
> >
> > I see no reason for this or byte&  byte to return an int. Since this would only cause C code to not compile, why not change it?

This should compile:

void main() {
   byte a = 5;
   byte b = 10;
   short c = 9;

   auto i = 5 & 10;
   auto j = ~c

   assert(typeof(i) == typeid(byte));
   assert(typeof(j) == typeid(short));

Because C code will not behave differently and since it is a smaller type it can only cause C code not to compile. And in reality it the change should only effect D code that uses type inference, but will not result in any broken code since byte is implicitly an int.

More information about the Digitalmars-d-learn mailing list