Disable implicit conversion

KennyTM~ kennytm at gmail.com
Mon Mar 7 06:29:51 PST 2011


On Mar 7, 11 18:33, Eugene wrote:
> Hi!
>
> What I want to do is pretty simple.  I need to subtract a ubyte from a
> ubyte and store the result in a ubyte.  The problem is that DMD
> implicitly wants to convert the ubytes into an integer, so it fails
> when attempting to store the result into a ubyte.  (Int cannot be
> converted to ubyte?)
> The error message I get:
>
> src\test.d(26): Error: cannot implicitly convert expression
> (cast(int)u2 - cast(int)u1) of type int to ubyte

ubyte u3 = (u2 - u1) & 0xff;
//                   ^^^^^^
//                   make sure the result fall in ubyte's value range


More information about the Digitalmars-d mailing list