Sign in to follow this  

typedef confusion

This topic is 3497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

This topic is 3497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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