Messages in this thread | | | Date | Fri, 07 May 1999 11:11:52 -0500 | From | ron flory <> | Subject | Re: fork() Problem? |
| |
"Richard B. Johnson" wrote:
> if(left = right) > > As stated, and as Lint picked up, we are now testing if the > assignment occurred, not the value of the left-most operand.
Careful. This is dead wrong. The assignment will always be made, othwise the compiler is flat broken. If we were testing whether the assignment was made, this expression would ALWAYS be true (which is NOT the case).
> Therefore, we have to make the assignment first: > > (left = right) ... Parenthesis for priority.
why, this is a simple assignment. there is nothing to prioritize here.
> if ( (left = right) ) > if ( (left = right) == 0 ) if ( left = right )
although the first and last are rather bad form, all three of these lines are functionally equiv, and will generate identical object code. The first simply contains a superfluous set of parens.
> The result of '==' is boolean which 'if' tests.
until recently, C/C++ did not have boolean values- it simply checks for non-zero results of the enclosing expression.
> Not only does Lint pick up this common error, but so does gcc if > you turn on all the error reporting with -Wall.
'if (a = b)' is not an error, it is however sloppy form.
ron
as if this silly thread needs another set of opinions- it is a CS201 issue. Please consult the instructor-
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |