Overflow-safe use of unsigned integral types
rumbu
rumbu at rumbu.ro
Mon Nov 11 02:33:15 PST 2013
On Monday, 11 November 2013 at 07:52:34 UTC, luka8088 wrote:
> Just for reference:
> http://forum.dlang.org/thread/kn3f9v$25pd$1@digitalmars.com
Again, this has nothing to do with runtime overflow checking.
It's a compiler thing. It will be nice if the compiler will not
accept implicit conversions from signed types to unsigned ones
for negative values. An explicit cast can be used if someone
wants to represent a negative number as unsigned.
Another consequence of this behaviour is the impossibility to
select automatically an overload for signed and unsigned
arguments:
void foo(ulong x) {}
void foo(long x) {}
foo(-3) //=> error, both match
More information about the Digitalmars-d-learn
mailing list