views:

115

answers:

2

what is the difference between these two below:

typedef void (*my_destructor)(void *);

typedef void (*my_destructor)(void *)  my_func_ptr;

is the second one valid?

+7  A: 

The first one declares a type called my_destructor. This type is a pointer to a function taking a parameter of type void* and returning nothing.

The second one is not valid, what are you trying to do ? If you want to declare a variable of type my_destructor, you have to do this:

typedef void (*my_destructor)(void *);
my_destructor my_func_ptr;
Samuel_xL
Or just `void (*my_func_ptr)(void*);`, if you want to declare a variable of that type without naming the type. But really you should name function-pointer types, because it's a lot of error-prone hassle to keep repeating them in full all over the place.
Steve Jessop
+1  A: 

You are declaring a type for a pointer function. The first one is the good one it mean you have a type named my_destructor who is a pointer to a function (*my_destructor) that take a void pointer (void *) on arguments and who return nothing (void).

Now you can use your type as if it was another type like for example char, long or whatever.

Patrick