What's the meaning of typedef int function(void*)?

I saw some BSD code using the following construct:

typedef int driver_filter_t(void*);

What does that mean, exactly? I don't think it's a function pointer because otherwise it would be something like typedef int (*driver_filter_t)(void*), right?

Answers


typedef int driver_filter_t(void*);

This is a definition of a function type. It makes driver_filter_t an alias for the type that can be described as "function returning int with an argument of type pointer to void".

As for all typedefs, it creates an alias for an existing type, not a new type.

driver_filter_t is not a pointer type. You can't declare something of type driver_filter_t (the grammar doesn't allow declaring a function using a typedef name). You can declare an object that's a function pointer as, for example:

driver_filter_t *func_ptr;

Because you can't use a function type name directly without adding a * to denote a pointer type, it's probably more common to define typedefs for function pointer types, such as:

typedef int (*driver_filter_pointer)(void*);

But typedefs for function types are pefectly legal, and personally I find them clearer.


Need Your Help

assignment from incompatible pointer type eclipse

c eclipse pointers ubuntu

I have seen many questions on this topic, but couldnt take much sense from them and couldn't compare it to my code. I'm not sure what I'm doing wrong, but it appears as a warning on eclipse, and I ...

iOS -custom xib file not appearing as inputAccessoryView of UITextField

ios iphone xcode uiview interface-builder

I'm following this video (except im linking the custom view in code not in IB), but I'll explain what's happening. I have created a custom view that extends off UiView. It is created from an xib fi...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.