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

  • SEARCH
  • Home
  • 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 8482343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:48:05+00:00 2026-06-10T19:48:05+00:00

Suppose there’s a list of arguments stored somehow, in a array for example. Given

  • 0

Suppose there’s a list of arguments stored somehow, in a array for example.

Given a function pointer, how could I make a call to it passing the stored list of arguments?

I’m not trying to pass the array as an argument ok. You got it, ok? I want to pass each of its elements as an argument. An array is just to illustrate, I could be storing the arguments in some tuple structure. Also, look that I have at hand a function pointer and may have a signature in string format. I’m not trying to just define a function that is able to deal with a variadic list.

The only way I see how to do that is by employing assembly (by __asm push et al.) or this:

void (*f)(...);

int main()
{
    f = <some function pointer>;
    int args[]; <stored in a array, just to illustrate>
    int num_args = <some value>;

    switch(num_args)
    {
        case 0:
            f();
        break;

        case 1:
            f(args[0]);
        break;

        case 2:
            f(args[0], args[1]);
        break;

        /* etc */
    }

    return 0;
}

I don’t like this approach too much…

Is there another portable and shorter form?

Several script languages are able to call C functions.

How script languages like Python or Ruby do that? How they implement it in a portable way? Does they just use assembly for several platforms or the above in the end?

Look that I’m really not asking about details of parameter marshaling and other stuff from script languages to C, I’m interested only in how, in the end, internally, the call to the C function by the script language is built.

EDIT

I’ll keep the question’s title but I think a better way for asking it is:

How to call a C function with its pointer and signature available only at runtime?

UPDATE

From Foreign Interface for PLT Scheme:

A call-out is a normal function call. In a dynamic setting,
we create a “call-interface” object which specifies (binary)
input/output types; this object can be used with an arbitrary
function pointer and an array of input values to perform a callout to the function and retrieve its result. Doing this requires
manipulating the stack and knowing how a function is called,
these are details that libffi deals with.

Thanks @AnttiHaapala for searching, finding and pointing libffi. It’s what I was looking for, it’s being used by a bunch of script languages, it’s a portable library, implemented across several architectures and compilers.

  • 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-10T19:48:07+00:00Added an answer on June 10, 2026 at 7:48 pm

    I am the author of libffi. It will do what you are asking.

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

Sidebar

Related Questions

Suppose there is a list of ranges of numbers, for example, {0,9},{14,18},{19,30}. And I
Suppose there is a function pointer: void func(float a1, float a2) { } void
suppose there is a string of characters in an array of d[20] . How
Suppose there are several boost strand share_ptr stored in a vector m_poStrands. And tJobType
Suppose there is an array, we want to find everything in the odd index
Suppose there is given two String: String s1= MARTHA String s2= MARHTA here we
Suppose there is a unsorted array A, and it contains an element x (x
Suppose there are 3 strings: protein, starch, drink Concatenating those, we could say what
Suppose there exists a function which returns a message say of the following format:
Suppose there is a string of type NSSTring NSString *string; There is array called

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.