On 2005-04-10 at 13:45:50 Daniel Ellard wrote: >> int main(void) { >> int a; >> a+=1; >> return (0); >> } [snip] > If you change the -O to -g, then the code for "a" is not > removed -- but there's still no warning. I think this is > a bug, because if the expression wasn't an innocuous a+=1 > it could be a real problem if the variable wasn't removed. The idea here is that gcc sees that the value of a is never used, and therefore it doesn't have to warn. (Whether you agree with this, or not, is more of a political or philosophical question. ;) But as soon as you actually *do* something with a's value afterwards, it will start to complain. IOW, if you change main into: int main(void) { int a; a += 1; a++; //...bunch of other operations on a... ++a; a *= 3; return 0; } and gcc will still issue no warning. However, add one actual *use* of a: extern void f(int i); int main(void) { int a; a += 1; f(a); return 0; } and you'll get the warning you want... :)
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:31 UTC