Local variables exists at least (and at most) inside functions. However, what happens to block-scope variables outside block but it the same function, could I keep and use their address? Is this code valid?
#include <stdio.h>
int main()
{
char *f;
if (1)
{
char q[] = "123";
f = q;
}
printf ("%s\n", f);
return 0;
}
In fact neither gcc -ansi -pedantic
nor valgrind complain on it, but could I use it cross-platform and cross-compiler? Seems to me no, but what tool could show me the error?
P.S. Should I use static
after all? It could be appropriate solution, but it seems to me not a thread safe one?