Thread: Runtime formation and execution at runtime

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2008
    Location
    PA, USA
    Posts
    11

    Runtime formation and execution at runtime

    Is there any way we can form and execute a statement at runtime in C?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, yes and no. You can't form a C expression and run it, but you could generate code at runtime - there is also no standard way of doing that, it changes both with processor architecture and OS architecture how you go about this.

    What are you actually trying to do? As in, do you have a particular problem you are trying to solve, and if so, can you explain what the problem is?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Location
    PA, USA
    Posts
    11
    There are three integer variables x1, x2 and x3 having values 1,2 and 3 respectively. Another fourth array variable x contains either x1, x2 or x3. I want to print the value of the variable which is the value of x. e.g. if x contains x2, I want to display 2. (Of course this is a simplification of a bigger program).

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sounds like all you need is a pointer to the right variable [somehow you must know which variable you want printed somewhere, right?]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Location
    PA, USA
    Posts
    11
    Yes.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So I take it that solved the problem?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Tags for this Thread