#Passing a function pointer as an argument

23 messages · Page 1 of 1 (latest)

shrewd zealot
#

i keep getting this error:

void get_guess_position(int search_min_x, int search_max_x, int search_min_y, int search_max_y, int (*is_available)(int, int), int *guess_x, int *guess_y); is the function prototype i have to use.

this is where i'm calling the function:

int (*fn_ptr)(int, int);
fn_ptr = &is_available;

void get_guess_position(west, east, south, north, is_available(*guess_x,*guess_y), guess_x, guess_y);

where is_available is defined as: int is_available(int x, int y);

grizzled egretBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

shrewd zealot
#

side question: how do i make an asterisk display properly?

obtuse trellis
obtuse trellis
#

when you pass a pointer you don't reference it to pass it, nor should you call a function when passing it

#

;compile c void foo(void()){} void bar(){} int main(){ foo(bar); }

warm krakenBOT
#
Compilation successful
obtuse trellis
#

for example

#

instead of foo(bar()), that's trying to pass the result of bar to foo

shrewd zealot
#

i had tried that but it didn't work either

obtuse trellis
#

what error did you get

obtuse trellis
shrewd zealot
#

same thing, missing ')'

obtuse trellis
shrewd zealot
obtuse trellis
#

that's the issue then

#

you don't write the return type when calling a function

shrewd zealot
#

yeah lol it definitely is

#

i theoretically know that, i just keep making copy-paste errors

#

ty!

grizzled egretBOT
#

@shrewd zealot Has your question been resolved? If so, type !solved :)

shrewd zealot
#

!solved