dmd 1.046 and 2.031 releases

Jason House jason.james.house at gmail.com
Thu Jul 16 15:43:09 PDT 2009


bearophile Wrote:

> I'm playing with the new D2 a bit, this comes from some real D1 code:
> 
> void main(string[] args) {
>     int n = args.length;
>     ubyte m = (n <= 0 ? 0 : (n >= 255 ? 255 : n));
> }
> 
> At compile-time the compiler says:
> temp.d(3): Error: cannot implicitly convert expression (n <= 0 ? 0 : n >= 255 ? 255 : n) of type int to ubyte
> 
> You have to add a silly cast:
> 
> void main(string[] args) {
>     int n = args.length;
>     ubyte m = (n <= 0 ? 0 : (n >= 255 ? 255 : cast(ubyte)n));
> }
> 
> In theory if the compiler gets a smarter such cast can be unnecessary.
> 
> Bye,
> bearophile

add it to bugzilla. 


More information about the Digitalmars-d-announce mailing list