Correct comparison of signed type with unsigned type (and vice versa)
ponce
contact at gam3sfrommars.fr
Fri Feb 21 02:51:34 PST 2014
On Thursday, 20 February 2014 at 22:52:55 UTC, Meta wrote:
> I can't think of any C code that would rely on such behaviour,
> but I think it'd just be safer all-around to make it an error.
Eg this optimization:
if ((unsigned int)(a - min) < (max - min)) // only one
comparison instead of two
{
}
And there is many C codes relying on unsigned promotion, since
signed overflow in C99 is undefined behaviour. The easiest way to
force an operation is then to use one cast.
More information about the Digitalmars-d
mailing list