News for hackers. Stuff that matters.
Re:Worst Bug Ever by mpyne on Monday January 21, 2013 @01:21PM (#5092803)
TRUE is going to be 1. The flag value might have the value 0x2, 0x4, 0xsomething_else, etc., which will not equal exactly 1 (TRUE).

What you want varies but is probably something like:

    if (flag & FLAG_VALUE) ...
    if (flag) ....
    if ((flag & FLAG_VALUE) == TRUE) ...
that kind of thing.
Re:Worst Bug Ever by geon on Monday January 21, 2013 @03:51PM (#5093691)

    if ((flag & FLAG_VALUE) == TRUE) ...
That would still check if flag is 1, right?
Re:Worst Bug Ever by azth on Monday January 21, 2013 @04:04PM (#5093754)
That is correct.
Re:Worst Bug Ever by mpyne on Monday January 21, 2013 @09:23PM (#5095147)
Indeed, great catch (this is why I use things like QFlags now, as it has a simple "testFlag" method)
Re:Worst Bug Ever by to3m on Monday January 21, 2013 @04:43PM (#5093905)
flag&FLAG_VALUE will be FLAG_VALUE or 0, so unless FLAG_VALUE==TRUE the answer could be wrong.

Suggest (flag&FLAG_VALUE), or, if you need the expression to be of type bool, ((flag&FLAG_VALUE)!=0) or (!!(flag&FLAG_VALUE)).

Re:Worst Bug Ever by mpyne on Monday January 21, 2013 @09:24PM (#5095151)
Very true, I just checked to see if I can edit but I can't, so mea culpa.
Re:Worst Bug Ever by ja27 on Monday January 21, 2013 @09:58PM (#5095262)
Boolean true / TRUE wasn't defined in any standard way before C99. Back in the "olden days", most programmers #defined it as 1, but not always. I ran into one of those "not always" cases in some inherited code.