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

Ask A Question

Stats

  • Questions 220k
  • Answers 220k
  • 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 The fact that you didn't set up the MOC is… May 12, 2026 at 11:56 pm
  • Editorial Team
    Editorial Team added an answer Read this article What you can do most simply is… May 12, 2026 at 11:56 pm
  • Editorial Team
    Editorial Team added an answer \makeatletter \def\opening#1{\ifx\@empty\fromaddress \thispagestyle{firstpage}% {\raggedleft\@date\par}% \else % home address \thispagestyle{empty}% {\noindent\let\\\cr\halign{##\hfil\cr\ignorespaces… May 12, 2026 at 11:56 pm

Related Questions

I'm struggling to create a generic (or untyped) array in C (I'm aware that
As a follow on from this question. How can I call a function and
Can someone help me? I am trying to do something like the following: #include
I have an XML file (on the left) and I want to create multiple

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.