warning: suggest parentheses around assignment used as truth value [closed]

The compiler is warning you that the result of the expression x = y is used inside a conditional; I mention this even though it does not appear to be related to your actual question because these days, usually it means that there’s a typo and the author meant to write == instead.

Regarding the question: since x = y evaluates to y (a double) and y is zero, the result is false because that’s what the C standard says should happen. From 6.3.1.2:

When any scalar value is converted to _Bool, the result is 0 if the
value compares equal to 0; otherwise, the result is 1.

So running this code should not print the “equals” message, as indeed it does for me.

Leave a Comment