Like Tree1Likes
  • 1 Post By Sebastiani

"Puppet Program" Question

This is a discussion on "Puppet Program" Question within the C Programming forums, part of the General Programming Boards category; Hello, I have a concise question. I have a semantically correct code in a program file (foo.c). I have a ...

  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,703
    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:
    bool flip(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(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,703
    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...
    SirPrattlepod likes this.
    Code:
    bool flip(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(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, 07: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, 06:59 AM
  5. Question about "Answer Key" Program
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 11-14-2001, 08:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21