lkml.org 
[lkml]   [1999]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: fork() Problem?
Richard B. Johnson writes:
> 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. Therefore, we have
> to make the assignment first:

I don't know where you got this idea, and it seems to be the root
of your misconception, but C has no such mechanism for "testing
if the assignment occurred." Assignment returns the value
assigned to the left operand, not a truth value indicating
whether the assignment occurred or not. The standard is quite
clear about this. If you say

if (left = right)
and 'right' is 0, then 0 is assigned to 'left' and the value of
the expression 'left = right' is 0, which the 'if' then regards
as false per the C rule that zero is false and non-zero is true.
Otherwise the commonly-used (and generally considered to be
stylistically valid) construct "a = b = c = d = 0" would not
behave as expected. If you don't believe me, try it in your
favorite standard-compliant C compiler.

Your lint tool is right to complain about using 'a=b' alone in a
conditional context on stylistic grounds, and I would generally
avoid using such a construct or recommending that anyone else use
it, but the point is that it is syntactically and semantically
valid C by both the K&R and ANSI standards, and your stated
interpretation of the behavior of the construct is wrong and
misleading.

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

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.126 / U:0.136 seconds]
©2003-2011 Jasper Spaans