Jump to content
  • Advertisement
Sign in to follow this  
ICUP

typedef confusion

This topic is 3718 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!