Re: fork() Problem?

Dustin Marquess (jailbird@alcatraz.fdf.net)
Wed, 5 May 1999 23:34:41 -0500 (CDT)


On Wed, 5 May 1999, Richard B. Johnson wrote:

[SNIP]
> Again, after the assignment was made, there was no check of the
> value. This is what Lint picked up. When you read the standard,
> it talks about the value of the left operand. It also talks about
> its type because of the promotion rules, that's all your cited
> text shows.
>
> Here we have a compound statement in which an assignment is
> being made, i.e.,
>
> left = right;
>
> Then we have a conditional expression which tests the result of
> an operation:
>
> 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:

No. In your above example left is getting assigned the value of
right, and the whole if is returning THAT SAME EXACT VALUE. It is not
testing if the assignment was made (I don't see how one could fail), it's
testing the assigned value itself.

If assigned value is 0, it's false, if it's anything else, it's
true.

> if ( (left = right) ) ... exactly as Lint has shown.
>
> Lint shows that even this is an error because the result is
> not boolean. It really should be.

No.. C has no concept of 'boolean'.

The only difference between this example and the one above is the
extra formatting. They both function the same exact way.

> if ( (left = right) == 0 )
>
> The result of '==' is boolean which 'if' tests. It is, however,
> common usage to do:
>
> if(value)
>
> because there usually is a functional equivalent.

No.. these are opposites. The one that would be equiv. to the
first one would be "if (!value)".

> Not only does Lint pick up this common error, but so does gcc if
> you turn on all the error reporting with -Wall.
>
> xxx.c: In function `main':
> xxx.c:13: warning: suggest parentheses around assignment used as truth value

This is not an error. If it was an error the compiler would exit
and not produce code. This is a warning that is merely suggesting an
extra set of ()'s for formatting. The extra ()'s change the code
functionality IN NO WAY and this is NOT AN ERROR. Hence why it says
"warning".

-Dustin

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