Sign in to follow this  
ICUP

typedef confusion

Recommended Posts

Hello, my C++ book only briefly covered typedef for the purpose of legacy C code. So, I have a few questions about it. My understanding of typedefs is like this: typedef <data type> <alias> So, in this example: typedef int johndoe johndoe is now an alias for int, right? What about this: typedef int (*SDL_EventFilter)(const SDL_Event *Event); Would (*SDL_EventFilter)(const SDL_Event *Event); be an alias for int?

Share this post


Link to post
Share on other sites
Quote:
Original post by ICUP
What about this: typedef int (*SDL_EventFilter)(const SDL_Event *Event);

Would (*SDL_EventFilter)(const SDL_Event *Event); be an alias for int?

You're not going to like the answer ;(

No, that's a function pointer. The alias is SDL_EventFilter, and the data type is "a pointer to a function that returns an int and has takes one parameter which is a const SDL_Event*"

Share this post


Link to post
Share on other sites
Oh, ok, that makes sense.

So, if I have a function like this: int MyEventFilter( const SDL_Event *event );

Would it be correct to pass it on like this:

SDL_SetEventFilter( SDL_EventFilter MyEventFilter );

Also, (if you're familiar with SDL) how would I use this function? Supposedly it's for trapping events, but I have no idea what that means. I am familiar with waiting and polling events, but the idea of trapping events is still foggy.

My guess is that, inside the definition of a function such as MyEventFilter( const SDL_Event *event), depending on how the event structure is filled out, it will call on other function to perform some task. Like so:

int MyEventFilter( const SDL_Event *event )
{
if ( event.type == MOUSEMOTIONEVENT )
{ then do this... }

return 1 if successful, 0 if unsuccessful
}

If so, then what is the point of using SDL_SetEventFilter? Why not just create a function prototype that returns an int and takes an SDL_Event as a parameter?

Share this post


Link to post
Share on other sites
Everything you wanted to know (and did not want to know *g*) on function pointers: http://www.newty.de/fpt/index.html

Regards,
Andre

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this