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>
|