dmd 1.046 and 2.031 releases
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Jul 7 00:44:06 PDT 2009
Brad Roberts wrote:
>>> That's really cool. But I don't think that's actually happening (Or
>>> are these the bugs you're talking about?):
>>>
>>> byte x,y;
>>> short z;
>>> z = x+y; // Error: cannot implicitly convert expression
>>> (cast(int)x + cast(int)y) of type int to short
>>>
>>> // Repeat for ubyte, bool, char, wchar and *, -, /
>> http://d.puremagic.com/issues/show_bug.cgi?id=3147 You may want to add
>> to it.
>
> Before going too far, consider:
>
> byte x, y, z;
> short a;
> a = x + y + z;
>
> How far should the logic go?
Arbitrarily far for any given expression, which is the beauty of it all.
In the case above, the expression is evaluated as (x + y) + z, yielding
a range of -byte.min-byte.min to byte.max+byte.max for the parenthesized
part. Then that range is propagated to the second addition yielding a
final range of -byte.min-byte.min-byte.min to byte.max+byte.max+byte.max
for the entire expression. That still fits in a short, so the expression
is valid.
Now, if you add more than 255 bytes, things won't compile anymore ;o).
Andrei
More information about the Digitalmars-d-announce
mailing list