dmd 1.046 and 2.031 releases
John C
johnch_atms at hotmail.com
Thu Jul 16 06:29:54 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
Did you not read the change log?
"Implicit integral conversions that could result in loss of significant bits are no longer allowed."
More information about the Digitalmars-d-announce
mailing list