On Feb 9, 9:57pm, Alan Dayley wrote:
> It is one of my cardinal rules: Always
> step through new code at least the first time you run it. I can save loads
> of time, especially on the dumb errors like:
>
> if (foo = 0)
> {
> ...
> }
The -Wall option to gcc (or -Wparentheses if you don't want the rest of
the -Wall options) will warn you about this kind of construct. E.g...
saguaro:ctests$ gcc -c dumb.c
saguaro:ctests$ gcc -Wall -c dumb.c
dumb.c: In function `f':
dumb.c:6: warning: suggest parentheses around assignment used as truth value
Here's dumb.c:
extern void g(void);
void
f (int foo)
{
if (foo = 0)
g ();
}
Generally, it's a good idea to make your code compile cleanly with
-Wall. The compiler will find all sorts of problems with your code
if you let it.
Kevin