I got a warning from vs2010 at compile time (C4172 returning local variable or temp)
int foo(){
int* bar = Bar()
}
int* Bar(){
int array[2];
array[0] = 1;
array[1] = 2;
return array;
}
if I understand the reason for this correctly, that the array 'array' in Bar function
is freed for use immediately after the return from the function.
My question is how to deal with this?
I'm wondering if using the static keyword will help..
int* Bar(){
static int array[2];
array[0] = 1;
array[1] = 2;
return array;
}
... and keep the address and its contents available to the calling function 'foo()'
until the function 'Bar()' is called again?
Just after a tip for the safest way to deal with it.
Appreciate any comments.