Implicit integer casting

Kevin Cox kevincox.ca at gmail.com
Sun Mar 18 12:17:59 PDT 2012


On Mar 18, 2012 3:09 PM, "Manu" <turkeyman at gmail.com> wrote
> int x = 123456;
> x &= 0xFF; // x is now in range 0..255; now fits in a ubyte
> ubyte y = x; // assign silently, cast can safely be implicit

This is related to Go's infinitely sized constants.  If an expression
produces a value out of range then brings it back in range in a constant it
still works.

int i = 1 << 100 >> 98;
assert( i == 4);

Not exactly related but similar idea.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120318/6705b365/attachment.html>


More information about the Digitalmars-d mailing list