Re: fork() Problem?

David Luyer (luyer@ucs.uwa.edu.au)
Thu, 06 May 1999 11:19:46 +0800


> Even 'gcc' knows that the operation is incorrect, but you have to
> turn on -Wall.
>
> xxx.c: In function `main':
> xxx.c:13: warning: suggest parentheses around assignment used as truth value

It knows it is a 'strange' piece of code and hence gets a warning. It's
not actually an illegal thing to do. Even -ansi -pedantic -pedantic-errors
doesn't error or warn on it without the -Wall.

To make gcc 'happy' you write

if ((pid = fork())) ...

instead of

if (pid = fork()) ...

so that it is absolutely clear what you mean. This is just like gcc
warning about addition within << and >> since some people don't realise
the precedence rules there. Only this one is more designed to catch
typos and Pascal converts.

test.c:3: warning: suggest parentheses around + or - inside shift
test.c:3: warning: suggest parentheses around assignment used as truth value

Note the "suggest". This is completely valid code which is possibly
unclear to the reader, or a common source of mistakes. Similarly
gcc warns about using (signed) chars as array indexes, when there's
nothing wrong with it except that you might have forgotten that they
are signed and accidentally access before the array start point.

David.

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