Saving compiled code
Hi all!
I want to save compiled code but don''t know how it works.
For example:
void test()
{
printf("Hello!");
}
void* pvoid;
void main()
{
pvoid = (void*)test;
FILE* f;
f = fopen("test.txt","w+b");
// saving my void here!!
fclose(f);
}
Okay, hope you understand what I want to do. I can save the void, that''s not the problem but how do I know which size it has? The sizeof() operator doesn''t work so... Can anyone help me??
Greetings
Corrail
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
I''m sorry, I don''t think anyone here is going to be able to figure out specifically what you''re trying to do.
Are you trying to write the code for the test function to a file? If so, then I''d like to say that the only reason I can think of to do this would be for a virus. Otherwise, why?
Secondly, you''ve already got the compiled code in a file, the file that is generated from the compiler (most likely an EXE).
Are you trying to write the code for the test function to a file? If so, then I''d like to say that the only reason I can think of to do this would be for a virus. Otherwise, why?
Secondly, you''ve already got the compiled code in a file, the file that is generated from the compiler (most likely an EXE).
No, I''m not going to write a virus.
I want to create a model file format with functions included. I want to try it because of dynamics and speed advantages! I want to save different functions for each model.
Corrail
corrail@gmx.at
ICQ#59184081
I want to create a model file format with functions included. I want to try it because of dynamics and speed advantages! I want to save different functions for each model.
Corrail
corrail@gmx.at
ICQ#59184081
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
I don''t think I can help much with saving compiled code like that into a model''s file. Seems like far more trouble than it''s worth. How many of these specialized functions do you really expect, and what do you want to compile them? Are your modellers really going to spend their time fighting with a tool to try to create these functions?
The Model Editor is going to be another problem... :-)
I don''t think that there''re many functions I want to save. Per model 3 or 4.
Corrail
corrail@gmx.at
ICQ#59184081
I don''t think that there''re many functions I want to save. Per model 3 or 4.
Corrail
corrail@gmx.at
ICQ#59184081
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
You won''t be able to do it like that with machine code compiled functions (at least not with a *lot* of headaches), memory protections, global memory layouts etc. all mean it is hard and very non-portable.
A better solution would be to use some sort of byte-code compiled language (e.g. LUA or a Lisp dialect, or Java, or any number of other languages), even then the functions will have restrictions on them.
A better solution would be to use some sort of byte-code compiled language (e.g. LUA or a Lisp dialect, or Java, or any number of other languages), even then the functions will have restrictions on them.
in your function:
void test() {
printf("Hello!");
};
void endOfTest() {
};
void (* funct)();
void main() {
funct = test;
int size = (int)(endOfTest - test);
FILE * f = fopen("test.txt","w+b");
fwrite(funct, 1, size, f);
fclose(f);
};
Basically, enfOfTest is a function directly after your test function. the compiler will align them right after each other in assembly codes. good luck
www.cppnow.com
void test() {
printf("Hello!");
};
void endOfTest() {
};
void (* funct)();
void main() {
funct = test;
int size = (int)(endOfTest - test);
FILE * f = fopen("test.txt","w+b");
fwrite(funct, 1, size, f);
fclose(f);
};
Basically, enfOfTest is a function directly after your test function. the compiler will align them right after each other in assembly codes. good luck

www.cppnow.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement