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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:11:37+00:00 2026-05-12T10:11:37+00:00

I am trying to do something like the following enum types {None, Bool, Short,

  • 0

I am trying to do something like the following

  enum types {None, Bool, Short, Char, Integer, Double, Long, Ptr};
  int main(int argc, char ** args) {
     enum types params[10] = {0};
     void* triangle = dlopen("./foo.so", RTLD_LAZY);
     void * fun = dlsym(triangle, ars[1]);

     <<pseudo code>>
  }

Where pseudo code is something like

fun = {}
for param in params:
      if param == None:
         fun += void
      if param == Bool:
          fun += Boolean
      if param == Integer:
          fun += int
      ...
 returnVal = fun.pop()
 funSignature = returnval + " " + funName + "(" + Riffle(fun, ",") + ")"
 exec funSignature

Thank you

  • 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-12T10:11:38+00:00Added an answer on May 12, 2026 at 10:11 am

    Actually, you can do nearly all you want. In C language (unlike C++, for example), the functions in shared objects are referenced merely by their names. So, to find–and, what is most important, to call–the proper function, you don’t need its full signature. You only need its name! It’s both an advantage and disadvantage –but that’s the nature of a language you chose.

    Let me demonstrate, how it works.

    #include <dlfcn.h>
    
    typedef void* (*arbitrary)();
    // do not mix this with   typedef void* (*arbitrary)(void); !!!
    
    int main()
    {
        arbitrary my_function;
        // Introduce already loaded functions to runtime linker's space
        void* handle = dlopen(0,RTLD_NOW|RTLD_GLOBAL);
        // Load the function to our pointer, which doesn't know how many arguments there sould be
        *(void**)(&my_function) = dlsym(handle,"something");
        // Call something via my_function
        (void)  my_function("I accept a string and an integer!\n",(int)(2*2));
        return 0;
    }
    

    In fact, you can call any function that way. However, there’s one drawback. You actually need to know the return type of your function in compile time. By default, if you omit void* in that typedef, int is assumed as return type–and, yes, it’s a correct C code. The thing is that the compiler needs to know the size of the return type to operate the stack properly.

    You can workaround it by tricks, for example, by pre-declaring several function types with different sizes of return types in advance and then selecting which one you actually are going to call. But the easier solution is to require functions in your plugin to return void* or int always; the actual result being returned via pointers given as arguments.

    What you must ensure is that you always call the function with the exact number and types of arguments it’s supposed to accept. Pay closer attention to difference between different integer types (your best option would be to explicitly cast arguments to them).

    Several commenters reported that the code above is not guaranteed to work for variadic functions (such as printf).

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

Sidebar

Related Questions

I don't know elisp, but I'm trying to do something like the following: (add-hook
I'm trying to find a useful design pattern that simulates something like this following:
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
I am trying to so something like Database Design for Tagging , except each
I've trying to achieve something like this: class Base { public: Base(string S) {
So I am trying to accomplish something like this: SELECT * FROM table WHERE
I'm trying to do a domain lookup in vba with something like this: DLookup(island,
I'm trying to create a user control that allows users to make something like
I'm trying to extract all matches from a EBML definition, which is something like

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.