Re: fork() Problem

Matt Stocum (mstocum@adelphia.net)
Thu, 06 May 1999 18:13:50 -0400


> From: "Richard B. Johnson" <root@chaos.analogic.com>
> Date: Wed, 5 May 1999 16:41:57 -0400 (EDT)
> Subject: Re: fork() Problem?

Ok first off, C has no way to check if the assignment succeeded.
Actually the only way I can think of that it wouldn't succeed is if you
use a function that returns void to assing a value. This shouldn't be
done anyway, and I'm pretty certain C will just assign 0 to the
variable, C++ won't even allow it. Second, C has NO bool type. All
boolean expressions are evaluated to false if the result is 0, true if
the result is anything else. Also, have you actually bothered to read
the Lint output you keep posting. The first "error" (it's really a
warning) is saying that you probally mean if(i==foo()) which is true.
People often use = when they mean ==, and the comment about the ()s is
to suppress the Lint warning, it has nothing to do with the C standard.
The second "error" is rather odd since it states that the expression is
not bool (which by C's definition of "bool" is wrong) and second states
that it is not int, which it clearly is. I'd say this is a bug in
LCLint rather than GCC. Read the standard, or ANY C book and you will
see that you are wrong.

-matt

> Not so. Your first instance tested if the assignment succeeded. It
> is a common error called 'boolean test of assignment' and is the
> most common error I've seen in 'C' coding.
>
> The next instance makes the assignment first, then makes a boolean
> test. This is actually another error which Lint will pick up. However,
> since a boolean type is commonly 'int', but not always, it is
> probably acceptable.
>
> #include <stdio.h>
>
> int foo()
> {
> return 0;
> }
>
> int main()
> {
> int i;
> if(i=foo())
> (void)puts("If this is not seen, it is a compiler BUG!");
>
> return 0;
> }
>
> This is the output from Lint which was configured to allow most
> 'gcc' anomolies to get through.
>
> LCLint 2.2a --- 04 Sep 96
>
> xxx.c: (in function main)
> xxx.c:13,5: Test expression for if is assignment expression: i = foo()
> The condition test is an assignment expression. Probably, you mean to use ==
> instead of =. If an assignment is intended, add an extra parentheses nesting
> (e.g., if ((a = b)) ...) to suppress this message. (-predassign will suppress
> message)
> xxx.c:13,5: Test expression for if not bool, type int: i = foo()
> Test expression type is not boolean or int. (-predboolint will suppress
> message)
>
> Finished LCLint checking --- 2 code errors found

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