0

I have a function prototype in a file. Is there any way to create a function pointer by reading the file at run time in c++?

3 Answers 3

2

You are properly looking for libffi, from Wikipedia:

libffi is a foreign function interface library. It provides a C programming language interface for calling natively compiled functions given information about the target function at run time instead of compile time. It also implements the opposite functionality: libffi can produce a pointer to a function that can accept and decode any combination of arguments defined at run time.

Sign up to request clarification or add additional context in comments.

2 Comments

Where can i find the details about libffi?
0

No. A function prototype is just a statement of how a function is used; it cannot be executed on its own.

If you have the name of a function and you want to turn that into a function pointer, you may be able to do so using dlsym(RTLD_DEFAULT, "fn"). Not recommended, though.

Comments

0

You could use a system call (using the system function of the standard library) to invoke a compiler which creates a dynamic library from your function file. You can then load the library with dlopen or LoadLibrary, depending on the platform.

EDIT: Of course this will not work if you really have only a prototype, and not the definition. In that case I am sorry I misunderstood your question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.