Say I have the following two functions:
1
int * foo()
{
int b=8;
int * temp=&b;
return temp;
}
2
int * foo()
{
int b=8;
return &b;
}
I don't get any warning for the first one (e.g. function returns address of a local variable) but I know this is illegal since b
disappears from the stack and we are left with a pointer to undefined memory.
So when do I need to be careful about returning the address of a temporary value?