Mail Archives: djgpp/2001/10/19/16:35:43
Dietmar Kuehl wrote:
>
> "Traveler" <traveler AT netti DOT fi> wrote:
>
... snip ...
>
> > #define AND &
> > #define EQUAL ==
>
> > As you can see the things "AND" & "OR" defined here are "bit" operators
> > not "logical" operators.
> > However, there really is no difference becourse you can use these two
> > just as easily in "if" statement?s as in bit manipulation.
>
> Nope, you cannot:
>
> if (ptr == 0 || ptr->something())
> ;
>
> will work correctly when being passed a corresponding null pointer while
>
> if (ptr == 0 | ptr->something())
> ;
>
> will not: It will "crash" (ie. invoke "undefined behavior") when applying the
> '->' operator.
>
> > All calculations done in computer, from the simplest addition to the
> > most complex 3rd grade (or greater) root solving uses these operator?s
> > and their compinations inside the microprocessor.
>
> This set of operations is enriched by additional operations like "jumps"
> which conditionally transfer operation to a different position. The logical
> operator are basically equivalent to multiple 'if' statements:
>
> if (cond1 && cond2)
> action();
>
> is equivalent to
>
> if (cond1)
> if (cond2)
> action();
>
> Likewise,
>
> if (cond1 || cond2)
> action();
>
> is equivalent to
>
> if (cond1)
> action();
> else if (cond2)
> action();
>
> (don't take this equivalence to literally: to deal correctly with "else"
> branches, things become pretty fast pretty ugly). The semantics of the
> corresponding bitwise operations do not involve anything like this.
>
> In general, you should follow the idioms used in a specific language, be it
> a programming language or a natural language: You will have a hard time to
> transfer idioms from one language to another like "he is heavy on wire" is
> completely meaningless in English because it is just a literal translation of
> a German idiom ("Er ist schwer auf Draht"; it was more in fashion a few years
> back). Although it may be easy to use literal translations (actually, I can't
> come up with a good English idiom although I'm sure there is one) these don't
> make sense. The same applies to computer languages!
As a point of order, what does that idiom mean (apart from the
literal). For an English sample, try "he is long in the tooth",
meaning (relatively) old. For its origin, think elephants.
C99 has sanctified much of the OP's desires. To use most of it on
both C90 and C99 I have the following header file "stdops.h":
/* Standard defines of operators, usable on C90 up */
#ifndef stdops_h
#define stdops_h
#if defined(__STDC__) && (__STDC_VERSION__ >= 199901L)
/* The following from C99 - must define for C90 */
#include <stdbool.h> /* define bool, true, false */
#include <iso646.h> /* define not, and, or */
#else
#define false 0
#define true 1
typedef int bool;
#define not !
#define and &&
#define or ||
#define xor ^
#endif
#endif
--
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT XXXXworldnet DOT att DOT net)
Available for consulting/temporary embedded and systems.
(Remove "XXXX" from reply address. yahoo works unmodified)
mailto:uce AT ftc DOT gov (for spambots to harvest)
- Raw text -