Here, I have defined two function pointers func1 and func2, and I guess this a way to use function pointers in c.But my question is when I call
executor(func1);
executor(func2);
How can I allocate memory for uint8_t * and pass it as an argument for either func1 and func2, so that I can use it back in main()
typedef int (*FUNC_PTR)(uint64_t, uint8_t*);
void executor(FUNC_PTR func)
{
uint64_t opts = 0x0000010;
uint8_t val = 0;
res = func(opts, &val);
}
int func1(uint64_t a, uint8_t* b)
{
//do some stuff
}
int func2(uint64_t a, uint8_t* b)
{
//do some stuff
}
void main()
{
executor(func1);
executor(func2);
}
executorneeds to take some extra argument(s) which will get passed tofuncand let the caller worry about the allocation.. Or use some global/static/dynamically allocated buffers. Which I would not recommend...