Is this reasonable?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Dec 5 17:06:29 PST 2013


On Thu, Dec 05, 2013 at 10:06:55PM +0100, Timon Gehr wrote:
> On 12/05/2013 07:26 PM, Jonathan M Davis wrote:
> >The best that could be done would be to warn about the comparison
> >or to make it an error.
> >
> >http://d.puremagic.com/issues/show_bug.cgi?id=259
> >...
> 
> The best that could be done would arguably be to simply do the
> comparison the 'right' way. E.g. static assert(-1 < 0u).

What's the 'right' way? assert(-1 < uint.max) will always fail because
no matter whether you convert to int or uint, the comparison simply
cannot be carried out at the machine code level. The only way you can
get a sane answer out of this is if the compiler translates it into:

	if (intVar < 0 || cast(uint)intVar < uintVar) { ... }


T

-- 
BREAKFAST.COM halted...Cereal Port Not Responding. -- YHL


More information about the Digitalmars-d-learn mailing list