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
  • size_t index=-1; Laeeth Isharc via Digitalmars-d-learn
    • Re: size_t index=-1; Mathias Lang via Digitalmars-d-learn
    • Re: size_t index=-1; Jonathan M Davis via Digitalmars-d-learn
    • Re: size_t index=-1; Steven Schveighoffer via Digitalmars-d-learn
      • Re: size_t index=-1; Mathias Lang via Digitalmars-d-learn
        • Re: size_t index... Steven Schveighoffer via Digitalmars-d-learn
          • Re: size_t i... Anonymouse via Digitalmars-d-learn
            • Re: siz... Johan Engelen via Digitalmars-d-learn
          • Re: size_t i... Mathias Lang via Digitalmars-d-learn
            • Re: siz... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... Marc Schütz via Digitalmars-d-learn
              • Re:... tsbockman via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... tsbockman via Digitalmars-d-learn
                • ... Jonathan M Davis via Digitalmars-d-learn
                • ... Jonathan M Davis via Digitalmars-d-learn
                • ... tsbockman via Digitalmars-d-learn
                • ... Basile B. via Digitalmars-d-learn
                • ... Ola Fosheim Grøstad via Digitalmars-d-learn
                • ... Basile B. via Digitalmars-d-learn

Reply via email to