4 ms·
Also how do you prevent "if(a=b)" if both sides are variables?
by greenhouse_gas 9y ago
Also how do you prevent "if(a=b)" if both sides are variables?
- ben509 9y agoI will let clang's amazingly detailed error messages speak for themselves: ben@burnination ~ $ cat test.c int main() { int a = 3; int b = 2; if (a=b) { return 1; } else { return 0; } } ben@burnination ~ $ clang -Wall test.c test.c:4:10: warning: using the result of an assignment as a condition without parentheses [-Wparentheses] if (a=b) { ~^~ test.c:4:10: note: place parentheses around the assignment to silence this warning if (a=b) { ^ ( ) test.c:4:10: note: use '==' to turn this assignment into an equality comparison if (a=b) { ^ == 1 warning generated.