- 1 year ago
Pass uint8_t* as parameter to raw function pointer
To pass a uint8_t*
as a parameter to a raw function pointer, you can declare the function pointer using the appropriate type signature. Here is an example:
c++void (*myFunction)(uint8_t*);
void myFunctionImplementation(uint8_t* data) {
// Implementation here
}
int main() {
myFunction = myFunctionImplementation;
uint8_t myData[] = {1, 2, 3, 4, 5};
myFunction(myData);
return 0;
}
In this example, we declare a function pointer named myFunction
that takes a single uint8_t*
parameter. We then define an implementation of the function named myFunctionImplementation
, which simply prints the value of the data parameter. Finally, we set myFunction
to point to myFunctionImplementation
, create a uint8_t
array named myData
, and call myFunction
with myData
as the parameter.
Note that the size of the uint8_t
array is not specified in the function pointer declaration, so it is important to ensure that the array passed as a parameter to the function pointer is of the correct size to avoid any issues with out-of-bounds memory access.