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:
- is it fine to assign to a pointer only a part of the structure created on stack?
- where is the foo structure? on stack? or heap?
- Is compiler smart enough to allocate only int[4] (which is quite unlikely) or it will alloc the complete foo?
- what is the time to live for my pa? Can I reliably use that pointer outside the process_a() function?
Thanks! Igor.