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 8505319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:17:03+00:00 2026-06-11T02:17:03+00:00

I need to make a function caller function: it receives a generic function pointer

  • 0

I need to make a “function caller” function: it receives a generic function pointer (void *) and a variable number of arguments as arguments and it’s got to call this function, passing the arguments, and return a generic pointer to the returning value. However, this entry-function pointer may point to any kind of function (with any returning type), even to functions with a constant number of arguments. It would be something like:

void * function_caller(void * function_pointer, ...) {
  void * returning_value;

  // Call the function and get the returning value

  return returning_value;   // this returning value will be properly casted outside
}

This way, the following code would work:

int function1(int a, char b) {
  // ...
}

void function2(float c) {
  // ...
}

float function3() {
  // ...
}

int main() {
  int v1;
  float v3;

  v1 = *(int *) function_caller((void *) &function1, 10, 'a');  // Which would be equivalent to v1 = function1(10, 'a');
  function_caller((void *) &function2, 3.0);    // Which would be equivalent to function2(3.0);
  v3 = *(float *) function_caller((void *) &function3); // Which would be equivalent to v3 = function3();

  return 0;
}

I know I’ll have to use a va_list, but I don’t know how to call the function by a pointer passing the arguments.

So, guys, any idea?

  • 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-06-11T02:17:05+00:00Added an answer on June 11, 2026 at 2:17 am

    The bad news is, this is not possible in C, even in unportable C. (GCC has extensions which sound like they do this job, but they do not work in the general case.) It is necessary to write assembly-language shims.

    The good news is, other people have already written the shims for you: have a look at libffi. (Manual here. Do not use the “closure” API if you can possibly avoid it.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make this function work everywhere, except IE6-7 $(function(){ window.scrollTo(0,300); }) Please
I need to make a Function that receives a Session Key and a Session
I need to make a stored procedure or function that returns a set of
I need to make a synonym search function, using MySQL. Here is the tables
I need to make the standard library function tolower static instead of public' scope.
I need to make some part of text bold while displaying in jquery: $(':checked').each(function()
I have two Ajax calls. I need to make sure that a JS function
What would i need to put in the SortIP function to make the custom
I'm writing a program in which I need to make sure a particular function
I need to make a number of calls to the YouTube API via AJAX

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.