Local variables exist at least (and no more) inside functions. However, what happens to the block variables outside the block, but this is one and the same function, can I save and use their address? Is this code valid?
int main()
{
char *f;
if (1)
{
char q[] = "123";
f = q;
}
printf ("%s\n", f);
return 0;
}
Actually gcc -ansi -pedanticneither valgrind nor complain about it, but can I use its cross-platform and cross-compiler? It seems to me not, but which tool can show me the error?
PS Should I use staticin the end? It may be a suitable solution, but it does not seem to be thread safe?
source
share