lkml.org 
[lkml]   [1999]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: fork() Problem?
Date
This is *not* a bug. lint is WARNING you (caps mine) that this may have
different results than expect. But the functionality behind the expression
is a C design feature that has been there since day one. Any compiler that
DOES execute the inside of the if() statement in the code you present would
be buggy.

--
Manuel A. McLure KE6TAW <mmt@unify.com>


-----Original Message-----
From: Richard B. Johnson [mailto:root@chaos.analogic.com]
Sent: Wednesday, May 05, 1999 12:11 PM
To: Steve VanDevender
Cc: linux-kernel@vger.rutgers.edu
Subject: Re: fork() Problem?


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.

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

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


I started to notice sloppy code being written this way several years
ago when 'gcc' started to allow it. Just because 'gcc' fixes bad code
doesn't mean it's the way to go (unless it fixes the source at the
same time).


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/

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

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.074 / U:0.436 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site