I have the following struct:
struct foo{
int a[4];
int b[4];
}
I have the following function:
foo get_foo()
{
foo ret_val;
<..some assignments here..>
return ret_val;
}
Now, my main code:
void* process_a()
{
int* pa = get_foo().a;
<..do smth with "pa"..>
return pa;
}
It appears that the code is running fine, but it is completely unknown what happens with complete structure, since I have access only to subpart of it. And, the questions:
Thanks! Igor.
pa
is the body of process_a
, but the lifetime of *pa
has expired as explained above.pa
for anything (except copying it) even inside process_a
.Your code appears to be running fine because "appears to be running fine" is a valid form of undefined behaviour, like anything and everything else.