Re: [AD] bool in MSVC

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Thu, Mar 25, 2010 at 4:14 AM, Chris Robinson <chris.kcat@xxxxxxxxxxxxxxxxx> wrote:

I think the latter could optimize better, given C's requirement for short-
circuiting. The former must not dereference 'display' if 'onoff' is false
(forcing a branch), whereas the latter can possibly optimize out any branching
because display->flags needs to be evaluated anyway.

Granted, I have no idea if this is time-sensitive code that would benefit from
such, but I figured I'd toss that out there.


I don't know where it's used either, but if it's inside an if statement anyway then avoiding the branching is probably not going to help much.

In any case the original version was wrong, but Peter's suggested alternative should be fine. Evert's needs another pair of parenthesis since != has precedence before &:

(onoff && ((display->flags & ALLEGRO_FULLSCREEN_WINDOW) != 0))

But if the intention of the code was as in the original statement it would have to be:

((onoff && ((display->flags & ALLEGRO_FULLSCREEN_WINDOW) != 0)) || (!onoff && ((display->flags & ALLEGRO_FULLSCREEN_WINDOW) == 0)))

So in that case I guess it's a bit unreadable...


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/