qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [7234] Use a more natural order


From: M. Warner Losh
Subject: Re: [Qemu-devel] [7234] Use a more natural order
Date: Thu, 23 Apr 2009 14:07:35 -0600 (MDT)

In message: <address@hidden>
            address@hidden (Lennart Sorensen) writes:
: > I've fixed several bugs like this over the years from coders that
: > thought this was a good way to program.
: > 
: > if (1 < x)
: > 
: > rather than 
: > 
: > if (x < 1)
: > 
: > is the most common pattern I've had to fix.
: 
: Then you were fixing the wrong problem.  The problem isn't the order,
: but simply that sometimes people get their logic backwards.  The correct
: fix would have been:
: 
: if (1 > x)
: 
: if in fact the logic was backwards.

No.  My fix was the correct one. :)

: > I find this argument unpersuasive when the compiler will already warn
: > me about if (x = 0).
: 
: Some compilers warn you.  Not all do.  An error from all compilers is
: also far better than a warning from some compilers.

In the absence of other side effects, yes.

: This is why people writing safety critical code in C require this order.
: It is simply the safest choice.

It isn't the safest order.  It is safer for one class of expressions,
more dangerous for the others.

I've also never seen that requirement in any of the works that I've
done, which has had safety implications...

Warner




reply via email to

[Prev in Thread] Current Thread [Next in Thread]