Hacker News new | ask | show | jobs
by harrytuttle 4648 days ago
What compiler flag is that? Genuinely interested. Wall,pedantic,ansi don't trigger it. I've tried the following and I don't get a warning or error:

   $ cat test2.c
   int main(int argc, char *argv[]) {
       if (argc = 0)
           return 1;
       return 0;
   }
   $ make test
   cc -Wall -ansi -pedantic    test.c   -o test
GCC version: gcc version 4.7.2 (Debian 4.7.2-5)
2 comments

  huh@px:/tmp$ cat a.c
  int main(int argc, char *argv[]) {
         if (argc = 0)
             return 1;
         return 0;
     }
  huh@px:/tmp$ gcc -Wall a.c
  a.c: In function 'main':
  a.c:2: warning: suggest parentheses around assignment used as truth value
Doesn't do that for me - what GCC ver and environment. Very odd! Digging in docs. Thanks for info.
It's some old-ish Debian on x86. GCC is 4.3.2.

But this is a such commonly-recognized pitfall that I actually don't know a single modern production compiler that does not generate this warning.

(edit) Just checked 4.7.1 and it generates the warning.

Thanks. I think this must be a config issue on this box. It makes me wonder what other warnings it is not telling me about.
Notice that you cat test2.c and then compile test.c.
Well spotted! Thanks for pointing this out!

I will now go and hit myself with a LART for a bit to remember not to do that again.