Re: fork() Problem?

Richard B. Johnson (root@chaos.analogic.com)
Wed, 5 May 1999 16:30:23 -0400 (EDT)


On Wed, 5 May 1999, Steve VanDevender wrote:

> Richard B. Johnson writes:
> > On Wed, 5 May 1999, Steve VanDevender wrote:
> >
> > > Richard B. Johnson writes:
> > > > > if (pid = fork())
> > > > ^^^^________ logical test of an assignment? This will always
> > > > be true!
> > >
> > > No. An assignment expression has the value of the value
> > > assigned. This allows expressions like a = b = c ('=' is
> > > right-associative). It will be true if the assigned value is
> > > true (nonzero), and false if the assigned value is false (zero).
> > >
> > > However, it is generally more clear and less error prone to make
> > > such tests explicit (i.e. (a = b) != 0).
> >
> > No. Definitely not! The gcc compiler 'fixes' very obvious and
> > awful bugs.
>
> Have you ever actually bothered to learn C or read the standards
> documents? This isn't the first time you've demonstrated your
> ignorance about fairly basic C behavior.
>
> This is not a 'bug' that gcc fixes. All properly
> standard-compliant C compilers behave this way because it is the
> defined standard behavior for the assignment operator.
>
> To quote the C Reference Manual (which is also the ANSI C
> Standard document) in _The C Programming Language, Second
> Edition_ by Kernighan and Ritchie:
>
> A7.17 Assignment Expressions
>
> There are several assignment operators; all group right-to-left.
>
> assignment-expression:
> conditional-expression
> unary-expression assignment-operator assignment-expression
>
> assignment-operator: one of
> = *= /= %= += -= <<= >>= &= ^= |=
>
> All require an lvalue as left operand, and the lvalue must be
> modifiable: it must not be an array, and must not have an
> incomplete type, or be a function. Also, its type must not be
> qualified with const; if it is a structure or union, it must not
> have any member or recursivly, submember qualified with const.
>
> The type of an assignment expression is that of its left
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> operand, and the value is the value stored in the left operand
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> after the assignment has taken place.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> So an assignment expression does have a value, and consequently
> can be legally used as a conditional expression in if, while, do,
> or for statements.
>
> In the future, Richard, please trouble yourself to do some real
> research rather than treating your personal opinions as
> incontrovertible facts.
>

No damnit! Look at the rules. Don't modify them to suit your
opinions.

#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;
}

Now, look what Lint has to say about this. The purpose of Lint
is to check rules. It has no opinion. It just checks rules.

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

Cheers,
Dick Johnson
***** FILE SYSTEM WAS MODIFIED *****
Penguin : Linux version 2.2.6 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

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