How to make gcc warn about returning the address of local variables?
问题 With gcc 4.4.5, I have a warning with the following code. char *f(void) { char c; return &c; } But, when I use a temporary pointer, there is no warning anymore (even if the behavior is wrong). char *f(void) { char c; char *p = &c; return p; } I heard that pointer-analysis is difficult in C, but can gcc warn about such code ? 回答1: Compilers, and most static analyzers, do not try to warn for everything wrong a program might do, because that would entail too many false positives (warnings that