Hacker News new | past | comments | ask | show | jobs | submit login

    $ echo 'int foo(int x, int y, int p) { if(x=y&&p) return -1; return 0; }' > test.c
    $ gcc -Wall -c test.c
    test.c: In function ‘foo’:
    test.c:1:1: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
This warning has been there since at least gcc 2.x, I believe.

I'm not making fun of you, really. But seriously: if you are spending 4 hours chasing bugs that can be trivially found by turning warnings on in your compiler, you have some process issues unrelated to C or PHP syntax.




It likes if ( (x = y) && p ) return -1;

(No, I don't have the exact statement in question handy. It was more complicated than this example.)


Yes, and that is because "(x == y) && p" should be written as"x == y && p" according to gcc. If you add the brackets gcc takes that as a sign that you really wanted to do an assignment.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: