Machine code for farmers who want their heads to spin.



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
.



Relevant Pages

  • Re: In what language do you think?
    ... In fact, photons are as real as molecules, and a distinction between ... representation; hence I doubt whether our sensual organs are involved ... recall some picture, music or odor, I neither see nor hear or smell. ...
    (sci.lang)
  • Re: Public data members = bad programming etc.
    ... I don't necessarily consider it bad programming. ... The internal representation might change. ... internals of the class, which must be different for different classes. ... It depends on whether the reference stays valid. ...
    (comp.lang.cpp)
  • Re: COMP3 Packed Decimals
    ... It's not really a C programming question, ... COMP-3, aka IBM packed decimal, is an integer data representation. ... It places one decimal digit in each of the successive four-bit groups ... bits of the octet at the lowest memory address. ...
    (comp.lang.c)
  • Re: Knowledge based programming? (Was: Thinking Recursion)
    ... >>> of current languages, for example the fact that most ... >>> needed in games programming etc. ... I'm always forced to choose the representation before ... > heap cell containing a pointer to a functor followed by arguments. ...
    (comp.lang.prolog)
  • Re: Knowledge based programming? (Was: Thinking Recursion)
    ... analyse common programming practices (such as ... > representation scheme for representing what you want applications to do ... to use than the target language, which is, in a way, also such ...
    (comp.lang.prolog)