1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Rep Power

    "Puppet Program" Question


    I have a concise question. I have a semantically correct code in a program file (foo.c). I have a semantically correct function in a header file (bar.h). The header file is not included in foo.c.

    Is there a known way to code a function in foo.c that can take in information regarding the function in bar.h, the function code itself, and use that information to execute all of the operations carried out by the function in bar.h without any pre-existing knowledge of what the code is exactly for the function in bar.h?

    Basically the goal is to have code in foo.c -- which has the code for the function in bar.h stored in a string -- generate the same activity as a version of foo.c in which the the code contains the function in bar.h.

    So I am asking if you all know of a way to have the function receive the code for the function in bar.h and carry out the same operations that are carried out by the function in bar.h.

    Any solution at all that allows a person to have a running program execute code input by a user would be appreciated.


  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Saint-Petersburg, Russia
    Rep Power
    No, nothing of the kind.

    H-files are simply included into your C-code files before compilation, so of course you can do nothing in runtime.

    C is not kind of a "scripting" language which allows to modify and execute its statements at runtime.

    You will need to write your own parser for function if you mean math function - or you will need to use some interpreter of some scripting language linked to your C program (to add plugins to your application). For example V8 javascript engine from google.

    You can also rewrite your application in any scripting language - Python, Javascript, PHP etc.

IMN logo majestic logo threadwatch logo seochat tools logo