Warp wrote:
>
> Dick Balaska <dic### [at] buckosoft com> wrote:
> : I have also seen #define TRUE ~FALSE
>
> This is horrible. It doesn't work!
>
> Suppose we have:
>
> #define FALSE 0
> #define TRUE ~FALSE
>
> Then TRUE will be -1 (ie. all bits set).
>
> Now suppose we want to add a "boolean" type:
>
> typedef int BOOL;
>
> This will NOT work as it should:
>
> int x=2, y=2;
> BOOL b;
>
> b = (x==y);
>
> if(b == TRUE)
> puts("Equal");
> else
> puts("Different");
>
> This will print "Different" although x and y are equal.
>
It is generally not good idea to compare against #define-d TRUE anyhow.
Better is to use != FALSE (although it is not very readable with its
double negative. Fortunately with C++ bool type this shouldn't be issue
any more.
Post a reply to this message
|