Messages in this thread | | | From | (Chris Adams) | Subject | Re: fork() Problem? | Date | 6 May 1999 00:00:23 -0500 |
| |
Once upon a time, Richard B. Johnson <root@chaos.analogic.com> said: >On Wed, 5 May 1999, Steve VanDevender wrote: >> Richard B. Johnson writes: >> > On Wed, 5 May 1999, Steve VanDevender wrote: >> > > Richard B. Johnson writes: >> > 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. >No damnit! Look at the rules. Don't modify them to suit your >opinions.
You keep "quoting" a particular version of lint as the official rules. Can you back up that this version of lint is 100% correct WRT to the ANSI C standard?
According to K&R2, a selection statement is of the form (where I've put _word_, the book uses italics):
if ( _expression_ ) _statement_ if ( _expression_ ) _statement_ else _statement_ switch ( _expression_ ) _statement_
_expression_: _assignment-expression_ _expression_ , _assignment-expression_
_assignment-expression_: _conditional-expression_ _unary-expression_ _assignment-operator_ _assignment-expression_
_assignment-operator_: = *= /= %= += -= <<= >>= &= ^= |=
And the text says "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, if you write
if (i = fork()) { /* do something */ } else { /* do something else */ }
the "i = fork()" is an assignment expression. Its value is the value of "i" after it gets the return value from fork(). According to the text for selection statements, the expression is evaluated and "if it compares unequal to 0, the first substatement is executed."
This is perfectly valid C. Doing this can be confusing and is usually in error where someone meant '==' instead of '=', so most compilers (and apparently your version of lint) warn about it.
>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)
Do you have a C++ lint instead of a C lint? This is warning about something not being a boolean type, which does not exist in C.
Basically, either your lint is trying to be helpful and give you warnings about possibly unintended things, your lint is broken and is giving errors about valid things, or you are trolling by complaining about problems with gcc that are really in your head. -- Chris Adams <cadams@ro.com> - System Administrator Renaissance Internet Services - IBS Interactive, Inc. Home: http://ro.com/~cadams - Public key: http://ro.com/~cadams/pubkey.txt I don't speak for anybody but myself - that's enough trouble.
- 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/
| |