Correct comparison of signed type with unsigned type (and vice versa)

Xinok xinok at live.com
Fri Feb 21 06:46:43 PST 2014


On Friday, 21 February 2014 at 10:45:50 UTC, ponce wrote:
> I don't see this as a bug, this is exactly what I expect from a 
> language with intact C integer semantics.

I didn't call it a bug. I said that it's prone to causing bugs.

> That subtly breaks C compatibility.

Personally, I wish we would drop some of the C semantics and 
allow the language evolve. In it's place, add a function 
attribute which would enable C semantics for the sake of 
migrating code.

> Currently in C the unsigned vs signed operations all follow the 
> same rules. If you do this, would you also disallow unsigned vs 
> signed addition, subtraction, divide?

Unfortunately, those operations don't have such simple solutions. 
D is a statically typed language and the compiler simply can't 
predict what the resultant type should be. However, comparisons 
do have a simple fix with minimal overhead.


More information about the Digitalmars-d mailing list