On Thursday, 17 March 2016 at 17:09:46 UTC, Steven Schveighoffer wrote:
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.

Strictly speaking yes, but typically, an `int` isn't used as a bit-pattern but as an integer (it's in the name). Such behaviour is very undesirable for integers.

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.

That's probably true, anyway.

  • 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
                • ... tsbockman via Digitalmars-d-learn

Reply via email to