|
![](/i/fill.gif) |
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.
You are a young pup.
And you are correct that this doesn't work on 2000 C compilers
because the (user) definition of TRUE doesn't match the system
definition.
But suppose you are working on a 6502 :) or a PDP-11, which can
deal with a -1 much easier than a 1; then it makes sense.
The PDP-11 is big-endian, so when you truncate a 1, you get 0
like down casting from int to word to char. The -1 always stayed
consistent across casts.
dik
Post a reply to this message
|
![](/i/fill.gif) |