Implicit integer casting

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Mar 18 12:53:56 PDT 2012


On 3/18/12, Manu <turkeyman at gmail.com> wrote:
> I'm finding that in this code I'm writing, casts are taking up more space
> on many lines than the actual term being assigned.

Another classic which fails to compile is:

import std.random;
ubyte c = uniform(0, 256);

In the call uniform returns a number anywhere from 0 to and including
255, which can fit perfectly in a ubyte. But I have to use a cast
(which is error-prone if I change the right interval), or use a
to!ubyte call (which is verbose). Granted for simple-purpose random
number generation a cast might be safe..


More information about the Digitalmars-d mailing list