Assum I have some pure C code like this.
It is not the real code, just for an example.
struct Param {
struct InParam {
int a;
int b;
} in;
struct OutParam {
int *c;
} out;
};
void MakeArray(struct Param *param) {
// just for filling the output param
for (int i = 0; i < param->in.a; ++i) {
param->out.c[i] = param->in.b;
}
}
int main() {
int *p = NULL;
special_memory_alloc(&p, sizeof(int) * 3)); // assume never failed
struct Param param = { {3, 4}, {p} };
MakeArray(¶m);
special_memory_free(p);
}
The function MakeArray
could within an independent module. I need the caller (eg. main
in this example) allocate the memories in out param for me.
So is there some way to hint users to do the allocation for the output param?