Thread: "Puppet Program" Question

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    2

    "Puppet Program" Question

    Hello,

    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.

    Thanks.

    -b
    Last edited by miasweb; 10-15-2013 at 11:02 PM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by miasweb View Post
    Hello,

    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.

    Thanks.

    -b
    The short answer is no. The long answer is that on some systems this is possible in certain limited contexts, but in any case is generally unportable and, well, unorthodox. Is there a reason you can't just include the header file (or create one to link to some external symbol)?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Oct 2013
    Posts
    2
    Quote Originally Posted by Sebastiani View Post
    The short answer is no. The long answer is that on some systems this is possible in certain limited contexts, but in any case is generally unportable and, well, unorthodox. Is there a reason you can't just include the header file (or create one to link to some external symbol)?
    It can be done.

    I'm trying to have a running program execute code input by a user.

    Let me know if you come up with a solution.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by miasweb View Post
    It can be done.

    I'm trying to have a running program execute code input by a user.

    Let me know if you come up with a solution.
    No thanks, I'll pass...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-19-2012, 06:15 AM
  2. Replies: 46
    Last Post: 08-24-2007, 04:52 PM
  3. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  4. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM
  5. Question about "Answer Key" Program
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 11-14-2001, 09:55 PM