enforce (i > 0) for i = int.min does not throw

kdevel kdevel at vogtner.de
Tue Jan 30 20:37:40 UTC 2018


On Sunday, 28 January 2018 at 19:17:49 UTC, Steven Schveighoffer 
wrote:
> This is insane. i > 0 is used in so many places. The only 
> saving grace appears to be that int.min is just so uncommonly 
> seen in the wild.

And another one that it does not happen when compiled with 
optimization (-O) and also that it does not affect all the ints:

---
import std.stdio;

void foo (T) ()
{
    auto i = T.min;
    writefln ("%12s: %24X %12s", T.stringof, i, i > cast(T) 0);
}

void main ()
{
    foo!byte;
    foo!short;
    foo!int;
    foo!long;
}
---

         byte:                       80        false
        short:                     8000        false
          int:                 80000000         true
         long:         8000000000000000         true

In 32 bit mode:

         byte:                       80        false
        short:                     8000        false
          int:                 80000000         true
         long:         8000000000000000        false



More information about the Digitalmars-d-learn mailing list