Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 799623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:09:32+00:00 2026-05-14T23:09:32+00:00

I’m trying to create a function pointer that takes a function pointer as an

  • 0

I’m trying to create a function pointer that takes a function pointer as an argument, but am not sure how to go about it… I was advised to try typedef-ing one of my function pointers, but get the same error. Could someone help me with the correct syntax?

    int
186 main(int argc, char **argv)
187 {
188   int             i;

194   typedef int   (*search_alg) (int *, int, int);
195   typedef int   (*search) (search_alg);
196   set_t         (*intersect_alg) (list_t *, (search));
197
198   clo_t          *iopts = parse_args(argc, argv);
199
200   /* select interstion algorithm */
201   switch (iopts->imode) {
202   case SVS:
203     fprintf(stdout, "ALGORITHM : SvS\n");
204     intersect_alg = svs;
205     break;
206   case SEQ:
207     fprintf(stdout, "ALGORITHM : Sequential\n");
208     intersect_alg = sequential;
209     break;
210   case ADP:
211     fprintf(stdout, "ALGORITHM : Adaptive\n");
212     intersect_alg = adaptive;
213     break;
214   default:
215     fprintf(stdout, "ALGORITHM : Unknown\n");
216     return (EXIT_FAILURE);
217   }
218
219   /* select fsearch algorithm */
220   switch (iopts->mode) {
221   case LIN:
222     fprintf(stdout, "F-SEARCH : Linear\n");
223     search = linear_fsearch;
224     break;
225   case BIN:
226     fprintf(stdout, "F-SEARCH : Binary\n");
227     search = binary_fsearch;
228     break;
229   case INP:
230     fprintf(stdout, "F-SEARCH : Interpolation\n");
231     search = interpolation_fsearch;
232     break;
233   case EXP:
234     fprintf(stdout, "F-SEARCH : Exponential\n");
235     search = exponential_fsearch;
236     break;
237   default:
238     fprintf(stdout, "F-SEARCH : Unknown\n");
239     return (EXIT_FAILURE);
240   }
241

244
245   /* perform intersection and run timings */
246   for (i = 0; i < iopts->runs; i++) {
248     /* perform intersect search */
249     intersect_alg (iopts->data_files, search);
252   }

The line I’m trying to make work is 249, I originally tried

int (*search_alg) (int *, int, int);
set_t (*intersect_alg) (list_t *, (*) (int *, int, int);

and would probably prefer to do it that way if possible. The error I’m getting is:

main.c:204: warning: assignment from incompatible pointer type
main.c:208: warning: assignment from incompatible pointer type
main.c:212: warning: assignment from incompatible pointer type

And the functions I’m pointing to are:

     22   /** Finger Search Operations for array sets **/
 23   int             linear_fsearch(int *set, int len, int key);
 24   int             binary_fsearch(int *set, int len, int key);
 25   int             interpolation_fsearch(int *set, int len, int key);
 26   int             exponential_fsearch(int *set, int len, int key);
 27
 28   /** Intersect Algorithms **/
 29   set_t          *svs(list_t * list, int (*srch_alg) (int *, int, int));
 30   set_t          *sequential(list_t * list, int (*srch_alg) (int *, int, int    ));
 31   set_t          *adaptive(list_t * list, int (*srch_alg) (int *, int, int));

Can anyone see what I’m doing wrong? I can’t figure it out.
Thanks!

Rhys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:09:33+00:00Added an answer on May 14, 2026 at 11:09 pm

    The declaration you need for intersect_alg is

    set_t *(*intersect_alg)(list_t *, int (*)(int *, int, int));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 388k
  • Answers 388k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've never found any, but the solution that I usually… May 15, 2026 at 12:18 am
  • Editorial Team
    Editorial Team added an answer It works for me. You probably have some other element… May 15, 2026 at 12:18 am
  • Editorial Team
    Editorial Team added an answer Just read only the first line, ignore the remnant and… May 15, 2026 at 12:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.