Why is int implicitly convertible to ulong?

Xinok xinok at live.com
Sun Feb 16 20:23:49 PST 2014


On Sunday, 16 February 2014 at 21:35:02 UTC, Hannes Steffenhagen 
wrote:
> isImplicitlyConvertible!(int,ulong) is true. Maybe this is just 
> me, but I get the impression that this is quite nuts. Why is an 
> implicit conversion from a signed to an unsigned type possible? 
> The other way round would be at least somewhat understandable 
> if there's a static check that the values actually fit.

IIRC, the way they put it is that "information is not lost," so 
you could always cast back to an int and get the original value. 
The same is not true for casting to a smaller type, e.g. int to 
byte, the original value may be lost.


More information about the Digitalmars-d mailing list