Behaviour of unsigned cast

Dan murpsoft at hotmail.com
Tue Apr 10 07:28:54 PDT 2007


Henning Hasemann Wrote:
> Im *not* saying it would be wise to have cast(uint) throw a runtime
> error when it is called on a negative value (though there are situations
> when this might be useful).
> But maybe the compiler should warn whenever cast(uint) is used
> (especially when this happens implicitly).

Walter so far has always tried not to use warnings.  I agree with his reasons.  

I think it's okay to cast an int to a uint implicitly *only* if the number is known to be positive.  Otherwise you're violating the semantics (value) of the number by casting it, and it should be explicit.

Ultimately, this again comes down to proveable bounds checking, as you can't necessarily cast a uint to an int because of the case int.max..uint.max

Somehow I don't see how cmp EAX, EBX knows what sign the operands are.



More information about the Digitalmars-d mailing list