Fawzi Mohamed wrote: > > On 13-apr-10, at 12:02, Don wrote: >> It's been part of DMD2 for a while now. It allows you to do things like: >> >> ubyte lowbits(int x) >> { >> return x & 7; >> } >> >> without an explicit cast. The compiler knows that x&7 can safely fit >> inside a single byte. Whereas ((x&7) << 12) | (x&3); >> does not fit, and requires an explicit cast. > > ah ok I understand, I thought that was treated like x & cast(ubyte)7 , > and so as comparison of the compile time value with the ranges of ubyte > (no range propagation needed). > But I can understand why it is treated as cast(ubyte)((cast(int)x) & 7), > as it is probably easier for the compiler, as it upcasts by default. > > Thanks for the explanation. > Note that in Don's example, "x" is an int, not a ubyte, so you don't need the cast to "int" in your second example, but you still need range propagation in the first...
Jerome -- mailto:jeber...@free.fr http://jeberger.free.fr Jabber: jeber...@jabber.fr
signature.asc
Description: OpenPGP digital signature