Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Pointer to function returning void

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Misery   Members   

354
Like
0Likes
Like

Posted 22 January 2012 - 04:12 PM

Hi there,

I am trying to make a function taking as one argument another function. This passed function is of type:

void SomeFunc(int blabla)
{
//do something
}


How do I define properly this function to which I pass the mentioned one? Is this fine?
SomeRetValuetype Func( void (AFunction(int)) )
{
	//do some stuff
   AFunction(someintvalue);
  //do some stuff
}

Is the example from above ok?
When I made this argument passing the way defined for other functions (as I did usually) I get a bunch of errors:
SomeRetValuetype Func( void (*AFunction(int)) )
{
	//do some stuff
   AFunction(someintvalue);
  //do some stuff
}

on GCC:

error: invalid conversion from 'void (*)(void*) {aka void (*)(void*)}' to 'void* (*)(void*)' [-fpermissive]|

Thanks in advance for any suggestions,
Misery

#2 Necrolis   Members   

1463
Like
3Likes
Like

Posted 22 January 2012 - 04:17 PM

its easier if you use a typedef:
typedef void (*myfunc_t)(int);

SomeRetValuetype Func( myfunc_t fp )
{
    fp(1);
}

or if you want to do it inline:

SomeRetValuetype Func( void (*fp)(int) )
{
    fp(1);
}


#3 Misery   Members   

354
Like
1Likes
Like

Posted 23 January 2012 - 12:34 AM

thanks,
I see the mistake: brackets were placed incorectly :-p




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.