Machine code for farmers who want their heads to spin.
- From: Charles Francis <charles@xxxxxxxxxxxxxxxx>
- Date: Tue, 27 Dec 2005 09:11:06 +0000
Thus spake Hamish <akc@xxxxxxxxxxxxxxx>
>
>"Charles Francis" <charles@xxxxxxxxxxxxxxxx> wrote in message
>news:3JBuduCBiFsDFwAA@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> 1 is true, 0 is false. I am a not little rusty. As I recall sometimes
>> truth is determined by the last bit of byte, in which case any odd
>> number would evaluate as true, and any odd number as false, but I think
>> I generally worked in languages, or chips, in which any nonzero number
>> evaluated as true.
>>
>
>
> It is generally bad programming to use or assume the underlying
>representation of values.
>
>Better to use only 'TRUE' and 'FALSE' in all the algorithms. I would not
>trust the compiler to pack booleans to single bits.
>It is probably true that FALSE == 0 and TRUE is > 0.
you forget values < 0
>
>I would (in c) use:
>
>#define TRUE 1
>#define FALSE 0
>
> if I wanted to be sure of the representation.
You can do that in c, but you still have to watch syntax. You may have
problems with stuff like
if (expression == TRUE)
or should that be
if (expression = TRUE) ?
which is completely different. Of course really you should write
if (expression | TRUE)
or should that be
if (expression || TRUE) ?
You wouldn't believe I programmed in C and C++ for more than five years
would you? I think I have thrown away my copy of Shoestrap if that was
his name. Of course it is even worse if you are working with someone
else's code, as you have to ascertain what whims he decided to follow
and how well he kept to them. This sort of thing is why I regard C and
C++ as absolute abominations, admired only by the muddle headed, and
completely unfit for any form of commercial programming. Which explains
precisely why they are the industry standard of course.
I did much work in assembler on DSPs. It is actually much better, as I
recall, to use
#define TRUE -1
i.e. FFFF.. or all bits equal to one. This is because if you have to
interrogate hardware it is likely that each bit is a flag representing a
different value, in which case you definitely need to be able to write
stuff like
if (expression | FLAG)
and have it evaluate as TRUE. This will normally be a part of the
machine code. You do not want to have to write extra code like
if ((expression | FLAG)!=0)
or should that be
if ((expression | FLAG)<>0)?
because
a) it will make your code harder to read
b) it will slow your code down.
An optimising compiler may improve b), but if you are writing machine
code DSP it is probably because speed is critical.
Regards
--
Charles Francis
Please reply by name
.
- Follow-Ups:
- References:
- Re: Odd dog days & Vets
- From: Charles Francis
- Re: Odd dog days & Vets
- From: Hamish
- Re: Odd dog days & Vets
- Prev by Date: Re: Happy Christmas!
- Next by Date: Re: Annual sheep & goat census
- Previous by thread: Re: Odd dog days & Vets
- Next by thread: Re: Machine code for farmers who want their heads to spin.
- Index(es):
Relevant Pages
|