delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/10/19/16:35:43

Message-ID: <3BD06798.8CC01450@yahoo.com>
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp
Subject: Re: Making C++ little easier to beginners...
References: <9qmkrh$581$1 AT tron DOT sci DOT fi> <5b15f8fd DOT 0110190333 DOT 616e0908 AT posting DOT google DOT com>
Lines: 101
Date: Fri, 19 Oct 2001 20:20:41 GMT
NNTP-Posting-Host: 12.90.174.229
X-Complaints-To: abuse AT worldnet DOT att DOT net
X-Trace: bgtnsc06-news.ops.worldnet.att.net 1003522841 12.90.174.229 (Fri, 19 Oct 2001 20:20:41 GMT)
NNTP-Posting-Date: Fri, 19 Oct 2001 20:20:41 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019