Re: fork() Problem?

Steve VanDevender (stevev@efn.org)
Wed, 5 May 1999 12:46:26 -0700 (PDT)


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.

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