Re: fork() Problem?

Alan Curry (pacman-kernel@cqc.com)
Wed, 5 May 1999 21:30:54 -0500 (EST)


Richard B. Johnson writes the following:
>>
>> "An assignment expression has the value of the left operand after
>> the assignment, but is not an lvalue."
>>
>> This means the expression "i=foo()" evaluates to whatever the value of
>> 'i' is after the assignment; if 'i' is zero, then the expression
>> evaluates to zero.
>>
>
>No it does not. It means, exactly what it says. It says that the
>type is that of the left operand (promotion rules) and the value
>is the value stored in the left operand after the assignment has
>taken place. It says nothing more.

i is `the left operand'. If foo() returns 0, i becomes 0. 0 is `the value
stored in the left operand'. Thus the value of the assignment is 0. 0 is a
false value, so if(i=foo()) { bar(); } will not call bar. What part of this
are you not getting?

>
>Even 'gcc' knows that the operation is incorrect, but you have to
>turn on -Wall.
>
>xxx.c: In function `main':
>xxx.c:13: warning: suggest parentheses around assignment used as truth value

gcc knows that mistyping = for == is a common mistake. It tries to guess when
you have made that mistake, and warns you about it. But the extra parentheses
do not make the code correct when it wasn't before. They are only a hint to
gcc that you don't want to see the warning. The actual meaning of the code is
unchanged.

-- 
Alan Curry

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