Updating Source in Real Time

EDIT: Thanks for everyone that tried to help and sorry for explaining this extremely bad since nobody was able to understand what I meant.

The Concept of "Rehashing" or "Reloading" is that of being able to modify the source of a running program and for it to self update on what you modified without having to stop it to recompile.

An example I tried to give was of you having

string Animal = "Dogs, Cats, etc."; somewhere in your program and it gets called.
You then compile and run this said program. You then go back and edit the source to say
string Animal = "No Animals"; and when the variable gets called again it will show the new modification you have done to it. Of course I don't mean for you to just change the string to something else and expect for it to self update. Nor do I mean there is a library or function for you to call for this to be accomplished.

This concept of reloading a program while it is still running is not a simple thing to do, the concept of it is advanced and a pain to accomplish.

As a side note, I don't know much PHP but from someone I know that does know it, he mentioned that when he implemented such feature on his program he had to read the variable through eval and some more php terminology I can't remember. He then showed me his program how it worked.

The way it functioned was that, He has a Function which held a variable (we'll call it func1). He then would call func1 to display the variable. He modified the variable in the func1 to say something else through the source file. Called a different function which reloaded func1 to update the modification he had done and then called func1 one more time to show the new modification he had done to it.

Once again I repeat that I have seen this done in C++ before so I know it's not impossible to do, just very complicated and not often seen. And I have a well understanding of C++ and am not new to it so I can grasp concepts and theory fairly quick.

Just as another side note, I have seen this feature mostly on languages such as php, python and perl. ones that don't need compilation. XD
Last edited on
I haven't met like this task until now...
"real time without having to recompile or restart " well.. I think the simplest way is read a string from keyboard and put to display in a loop.
As far as I know, that is impossible with C++. I think the only way to do it is changing the way C++ is programmed in. You'd pretty much be making a whole new language (or at least be changing most of C++). Maybe it wouldn't be that hard to do. I've never experienced a language that has what you want. Could you tell me what languages you've seen that have this feature?
I want to create a simple application that calls a function that couts "hi" or some other text. And then edit the function to cout something else, and run it again and show the modification
Variables are there for this reason...
You pretty much can't do your topic title. But you can do as screw suggested, and just read in a string and output or
what you could do is output a variable, add append and modify that same variable and output again....

If you explain what you have in mind rather than a simple:

cout << variable;
Last edited on
i think you're not clear enough..

tick wrote:
And then edit the function to cout something else

well i think you really dont have to edit the function to output something else, you just pass another string message as an argument then output it again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

void foo(string msg) {
    cout << msg << '\n';
}

int main() {
    while(true) {
        string tmp;
        getline(cin, tmp);
        foo(tmp); //call the function
    }
    return 0;
}

try compiling this code and tell us what you have in mind


tick wrote:
and run it again and show the modification

do you mean close the program then run it again?


it could also help if you tell us how much you know c++
The only way to do this would be to insert binary directly into the function. Unfortunately, you can only know how the compiler(s) you use work. You can't assume the way the linker works, either. How do you know that the object files that your compiler generates will be in the right order?

I think this is impossible in a high level compiled language; the only way to do it would be some major voodoo with assembly; and even then it'd be very sketchy.

In something like Perl or Python, however, it would be easy.
Thanks for all the help guys and sorry for the bad explanations.

I updated my first post to try to explain better. Thanks for all the ideas, I am just looking for the concept on this, I can do the rest.
in php you say? well php is a scripting language, it is just a plain text with a .php extension and don't need to be compiled so it is very easy to modify the source.

if you've really seen this happen in c++ then you might want to send me the exe file, then maybe just maybe i could help you.

here's another idea, lets say this is the compile file
1
2
3
4
5
6
7
8
9
10
11
[compiled.exe]
[program]
function() {
//read the string at the end of the file
//then modify it
}
[end of program]
[string]
1001010111001010//binary representation of string
[/string]
[/compiled.exe]


note: i have not tested this in c++ yet, only in vb6
Last edited on
Topic archived. No new replies allowed.