suggest parentheses around assignment used as truth value

Richard Earnshaw rearnsha@arm.com
Wed Jul 1 09:20:00 GMT 1998


> "Marc Rouaix" <rouaix@my-dejanews.com> writes:
> 
> |> I'd just like to register my opiniont that code like
> |> 
> |> if (x = p()) {...}
> |> 
> |> shouldn't generate a warning under gcc -Wall.
> 
> What if you have a typo here?
> 
> |>  Even if
> |> you feel that code like this is obscure, the recommended
> |> 
> |> if ((x = p())) {...}
> |> 
> |> is just bizarre.
> 
> Then write it as:
> 
> 	x = p();
> 	if (x) {...}
> 

Or,

	if ((x = p()) != 0) {...}

Then it becomes clear why the extra parentheses are needed.




More information about the Gcc mailing list