size_t index=-1;

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 17 10:09:46 PDT 2016


On 3/16/16 6:37 PM, Mathias Lang wrote:
> On Wednesday, 16 March 2016 at 21:49:05 UTC, Steven Schveighoffer wrote:
>> No, please don't. Assigning a signed value to an unsigned (and vice
>> versa) is very useful, and there is no good reason to break this.
>
> I'm not talking about removing it completely. The implicit conversion
> should only happen when it's safe:
>
> ```
> int s;
> if (s >= 0) // VRP saves the day
> {
>    uint u = s;
> }
> ```
>
> ```
> uint u;
>
> if (u > short.max)
>    throw new Exception("Argument out of range");
> // Or `assert`
> short s = u;
> ```

Converting unsigned to signed or vice versa (of the same size type) is 
safe. No information is lost. It's the comparison between the two which 
confuses the heck out of people. I think we can solve 80% of the 
problems by just fixing that. And the bug report says it's preapproved 
from Walter and Andrei.

VRP on steroids would be nice, but I don't think it's as trivial to solve.

-Steve


More information about the Digitalmars-d-learn mailing list