Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > getting around lack of bool type support

Reply
Thread Tools

getting around lack of bool type support

 
 
Keith Thompson
Guest
Posts: n/a
 
      12-29-2007
"Malcolm McLean" <> writes:
> "user923005" <> wrote in message
>
>> #define TRUE 1 #define YES 1
>> #define FALSE 0 #define NO 0

>
>> #define TRUE -1 is also very neat.


It would have to be
#define TRUE (-1)

> A single set bit is -1 in two's complement notation, but the real
> advantage is now we can say
> ~TRUE == FALSE.


-1 has *all* bits set, not a single bit. And I fail to see the
advantage of ~TRUE == FALSE. Surely !TRUE == FALSE is better.

Define TRUE and FALSE as 1 and 0 also matches the results of the
equality and relational operators (though of course any non-zero value
is true).

--
Keith Thompson (The_Other_Keith) <kst->
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Ivan Novick
Guest
Posts: n/a
 
      12-29-2007
On Dec 28, 5:39 pm, Chris McDonald <ch...@csse.uwa.edu.au> wrote:
> Ivan Novick <i...@0x4849.net> writes:
> >If you are trying to get existing code to compile and don't have bool
> >on your system try typedefing it.
> >typedef short bool
> >#define true 1
> >#define false 0

>
> (Serious question) why have you chosen to use a short (not a char, not an int)?
> Thanks,
>
> --
> Chris.


I agree, it should be char.

Regards,
Ivan Novick
http://www.0x4849.net
 
Reply With Quote
 
 
 
 
Army1987
Guest
Posts: n/a
 
      12-29-2007
Malcolm McLean wrote:

> "user923005" <> wrote in message
>
>> #define TRUE 1 #define YES 1
>> #define FALSE 0 #define NO 0

>
>> #define TRUE -1 is also very neat.

Why did you precede that line by >? it was not in the post you were
replying to. Btw, I'd add parentheses, just to avoid... er... TRUE[ptr]
do the wrong thing.

> A single set bit is -1 in two's complement notation, but the real advantage
> is now we can say
> ~TRUE == FALSE.

I fail to see why that's an advantage.
--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
Golden California Girls
Guest
Posts: n/a
 
      12-29-2007
Army1987 wrote:
> Malcolm McLean wrote:
>
>> "user923005" <> wrote in message
>>
>>> #define TRUE 1 #define YES 1
>>> #define FALSE 0 #define NO 0
>>> #define TRUE -1 is also very neat.

> Why did you precede that line by >? it was not in the post you were


Your newsreader must have missed a message

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      12-29-2007
Army1987 wrote, On 29/12/07 15:30:
> Malcolm McLean wrote:
>
>> "user923005" <> wrote in message
>>
>>> #define TRUE 1 #define YES 1
>>> #define FALSE 0 #define NO 0
>>> #define TRUE -1 is also very neat.

> Why did you precede that line by >? it was not in the post you were
> replying to. Btw, I'd add parentheses, just to avoid... er... TRUE[ptr]
> do the wrong thing.


Indeed.

>> A single set bit is -1 in two's complement notation, but the real advantage
>> is now we can say
>> ~TRUE == FALSE.

> I fail to see why that's an advantage.


Once upon a time in a land far far away there existed processors where
it made sense to use -1 for one of the two logical values. Well, the
land was not very far away, but processors have been able to do
efficient comparisons against 0 for a very long time, so it really was
long long ago.

Of course, as I said earlier comparing against TRUE is a very dangerou
thing to do. Doing it with TRUE defined as -1 is more dangerous because
the expressions ((1==1)==TRUE) would yield 0, i.e. false. So we have the
following:

if ((1==1) == TRUE)
puts("Not completely broken definition of TRUE");
else
puts("A completely broken definition of TRUE");

Will correctly report "A completely broken definition of TRUE".
--
Flash Gordon
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-29-2007
Golden California Girls <> writes:
> Army1987 wrote:
>> Malcolm McLean wrote:
>>
>>> "user923005" <> wrote in message
>>>
>>>> #define TRUE 1 #define YES 1
>>>> #define FALSE 0 #define NO 0
>>>> #define TRUE -1 is also very neat.

>> Why did you precede that line by >? it was not in the post you were

>
> Your newsreader must have missed a message


No, I just checked. The lines

#define TRUE 1 #define YES 1
#define FALSE 0 #define NO 0

were in user923005's message (quoted from the FAQ); the line

#define TRUE -1 is also very neat.

was not; it first appeared in Malcolm's message with a ">" prefix.

--
Keith Thompson (The_Other_Keith) <kst->
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      12-30-2007
Golden California Girls wrote:

> Army1987 wrote:
>> Malcolm McLean wrote:
>>
>>> "user923005" <> wrote in message
>>>
>>>> #define TRUE 1 #define YES 1
>>>> #define FALSE 0 #define NO 0
>>>> #define TRUE -1 is also very neat.

>> Why did you precede that line by >? it was not in the post you were

>
> Your newsreader must have missed a message

Even if it has, someone used a wrong number of > signs.
The lines " #define TRUE 1 #define YES 1" and "#define TRUE -1 is ..."
appear to be both by user923005, whose message I have, but the latter line
doesn't appear there.


--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
Golden California Girls
Guest
Posts: n/a
 
      12-31-2007
Army1987 wrote:
> Golden California Girls wrote:
>
>> Army1987 wrote:
>>> Malcolm McLean wrote:
>>>
>>>> "user923005" <> wrote in message
>>>>
>>>>> #define TRUE 1 #define YES 1
>>>>> #define FALSE 0 #define NO 0
>>>>> #define TRUE -1 is also very neat.
>>> Why did you precede that line by >? it was not in the post you were

>> Your newsreader must have missed a message

> Even if it has, someone used a wrong number of > signs.
> The lines " #define TRUE 1 #define YES 1" and "#define TRUE -1 is ..."
> appear to be both by user923005, whose message I have, but the latter line
> doesn't appear there.


It appears as if Malcolm started his response with a ">" character. Likely was
on the wrong line when he typed it. My newsreader does have a blank line
between his response and the quoted material above.
 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      01-01-2008
Golden California Girls wrote:

> Army1987 wrote:
>> Golden California Girls wrote:
>>
>>> Army1987 wrote:
>>>> Malcolm McLean wrote:
>>>>>> #define TRUE -1 is also very neat.
>>>> Why did you precede that line by >? it was not in the post you were
>>> Your newsreader must have missed a message

>> Even if it has, someone used a wrong number of > signs.
>> The lines " #define TRUE 1 #define YES 1" and "#define TRUE -1 is ..."
>> appear to be both by user923005, whose message I have, but the latter line
>> doesn't appear there.

>
> It appears as if Malcolm started his response with a ">" character. Likely was
> on the wrong line when he typed it. My newsreader does have a blank line
> between his response and the quoted material above.


And what I asked to Malcom was exactly why did he add a > at the beginning
of the line.

--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
Randy Howard
Guest
Posts: n/a
 
      01-01-2008
On Tue, 1 Jan 2008 11:06:17 -0600, Army1987 wrote
(in article <fldru9$tpn$>):

> Golden California Girls wrote:
>
>> Army1987 wrote:
>>> Golden California Girls wrote:
>>>
>>>> Army1987 wrote:
>>>>> Malcolm McLean wrote:
>>>>>>> #define TRUE -1 is also very neat.
>>>>> Why did you precede that line by >? it was not in the post you were
>>>> Your newsreader must have missed a message
>>> Even if it has, someone used a wrong number of > signs.
>>> The lines " #define TRUE 1 #define YES 1" and "#define TRUE -1 is ..."
>>> appear to be both by user923005, whose message I have, but the latter line
>>> doesn't appear there.

>>
>> It appears as if Malcolm started his response with a ">" character. Likely
>> was
>> on the wrong line when he typed it. My newsreader does have a blank line
>> between his response and the quoted material above.

>
> And what I asked to Malcom was exactly why did he add a > at the beginning
> of the line.


In the spirit of those "making mountains out of molehills", have you
all really never made a simple typo when editing a response to a long
threaded post with lots of different levels of '>>>>' indentation?

It happens. Furrfu.


--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
enum promote to bool type rather than Integer type? FE C++ 6 08-04-2009 03:21 PM
Name-brand DVD decks lack support RichA DVD Video 1 07-20-2005 02:05 PM
Lack of Support Stephen Boursy Firefox 4 03-11-2005 04:37 PM
Spam and ISP lack of support Silverback Computer Support 11 02-06-2005 10:21 PM
Working around a lack of 'goto' in python Brett Python 13 03-07-2004 08:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57