Is this reasonable?

Timon Gehr timon.gehr at gmx.ch
Fri Dec 6 05:01:31 PST 2013


On 12/06/2013 02:06 AM, H. S. Teoh wrote:
> 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
>

Yup, that's the 'right' way.


More information about the Digitalmars-d-learn mailing list