I'm reading linux kernel code and I encounter something like the following:
typedef void (* gps_location_callback)(GpsLocation* location)
then later it can be used like:
gps_location_callback location_cb;
Can somebody tell me what does that typedef mean? I never saw something like this before.. Thanks!
This is a function pointer. Variables of this type point to a function whose signature is void (GpsLocation*):
void foo(GpsLocation *);
gps_location_callback f = foo;
// now use f(p) etc
Without the typedef you'd have to write:
void (*f)(GpsLocation *) = foo;
It's making gps_location_callback as a typedef for a function that returns void and takes a GpsLocation* as an argument.
So any time you use ore declare a variable of type gps_location_callback, you're using or declaring a function pointer that points to a function that returns void and takes the arguments that the typedef lists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With