Passing an array of strings without copying
Hi,
I have two structs say:
Code:
struct a
{
int xyz;
char aStringArray[20][80];
};
struct b
{
bool b;
char ** aStringArray2;
};
Then I have a function that receives first struct as input and calls another function passing the second struct.
Code:
void exampleFunc1(struct a * mem_a)
{
struct b mem_b;
if (mem_a->xyz) mem_b.b = true;
else mem_b.b = false;
/* update mem_b.aStringArray2 using the info from mem_a*/
/* should I allocate the memory or I can use the memory already allocated for mem_a ? */
/* I know that mem_a will survive longer than mem_b */
/* call second function passing mem_b */
exampleFunc2(&mem_b);
/* if I allocated memory explicitly then destroy it now as we no longer need it */
/* mem_a memory is not headache of this function so let's return */
return;
}
Thanks for any ideas