Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typedef void(* something)(someclass* something) - what does that mean? Never seen typedef usage like this

Tags:

c

linux-kernel

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!

like image 858
Rachel Avatar asked Jan 28 '26 07:01

Rachel


2 Answers

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;
like image 194
Kerrek SB Avatar answered Jan 30 '26 22:01

Kerrek SB


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.

like image 37
Seth Carnegie Avatar answered Jan 30 '26 22:01

Seth Carnegie