realbasic-nug
[Top] [All Lists]

Re: C++ Libraries for RB (A little bit off)

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: C++ Libraries for RB (A little bit off)
From: Stefan Pantke <seaside dot ki at mac dot com>
Date: Fri, 31 Dec 2004 05:01:39 +0100
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <1906DF0E-5A9E-11D9-AB40-000A9578809A at epicodeinteractive dot com> <8FA065D8-5A9E-11D9-8A9B-000393101B4A at mobleybros dot com> <DCB0C160-5AA2-11D9-B1D0-000A95A0549A at comcast dot net> <20041230204517 dot 4DC7F76C69 at isis dot visi dot com> <722D5284-5AA6-11D9-863A-000A9585ABA2 at mac dot com> <20041230212422 dot E126876C69 at isis dot visi dot com> <EA59B996-5AB1-11D9-8513-000A95687284 at zhameesha dot com>

On 30. Dez 2004, at 23:26, Stuart Malin wrote:


On Dec 30, 2004, at 1:24 PM, Craig A. Finseth wrote:

Probably as either:

   int getMyNum(int fnum, int snum)
   {
   int tnum;
   tnum = fnum + snum;
   return tnum;
   }

or:

   int getMyNum(int fnum, int snum)
   {
   return fnum + snum;
   }

First, I apologize to everyone for forgetting the smily on my response.

   Why? The first code snippet is perfectly legal. Isn't it?
   Moreover, ill usage of = instead of == is a famous error in
   C/C++ coding ;-)

I'm not a C/C++ coder, but I am interested in this thread, and don't see the problem here.

The problem isn't of syntactical kind, but a good style question.

In C/C++ an expression can even be an assignment. Thus (n=m)+2 is perfectly
legal, while not too readable, since during the evaluation of ".."+2, a
side-effect is performed, the n=m assignment.

While this and increment/decrement operators like n++, ++n, n--, --n are sometimes useful when writing very low level code, complex code [ legal again ;-) ] like

        if ( ( --n = 42 ) = ( 15 = m++ ) )      {
                n = ( m = ( 2 + m ) )
        }

is hardly readable and very error prone.

I though == referred to equality testing, and so the famous error is in using = when a comparison was intended, causing an assignment. I don't see that in the above code snippets.

Your are right == is equality testing, and = is assignment. Thus, you are right.

Unfortunately, the original mail has already been moved into a black hole. Didn't some
code some messages earlier contained a problem? Don't know..

[BTW: When coding C - or ObjC like today - I always use constants left side of == expressions. Thus, if I type = instead of ==, the compiler fires an error.]


What I do see is the use of a locally scoped integer that isn't really necessary.

Right!

What am I not seeing?

I think you saw everything.

Kinds,

Stefan

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>