Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone knows how to do it...

Status
Not open for further replies.

CosmoGreco

Programmer
Sep 16, 2002
13
US
This is possible to achieve in C++. I just can’t figure out how to do it:

Dynamically generate a line of code stored in a string at run-time.

Example:

char *pszVar = “int iVar = 10;”;

Then, how to make the contents of pszVar come alive like a macro substitution so it will be a line of code like?

int iVar = 10;

Thanks,
Cos
 
What does "come alive" mean? And "come alive" where and when? You need to explain in more detail what you're trying to do...
 
Cosmo,

How many times are you going to ask the same question?

I'm sorry if you don't like the answers you have been provided with but they are correct.
 
georgemih,

I mean being able to perform a kind of macro substitution so the contents of pszVar is seeing at Run time as the statement int iVar = 10;

OK, you say it’s not possible to compile code at run-time perhaps, but it was accomplish before and I just would like to know the mechanisms or if there is any function available you guys know that make C++ transform a string containing a statement in a valid C++ line of code.

Other than that, this new question, I believe, was legit.

Although the other question I posted before “How to convert an arithmetic string expression to an int result” is related to this one, my goal at that time was to find a solution to convert a mathematical string operation using a most simple manner, in opposite of this new question that seeks to explorer a way to execute code generated dynamically, which would open innumerous possibilities to simplify our lives as programmers as I have seen before.

Pete, I appreciated your help by taking your time and answering my questions, but I want to believe that like me, most programmers don’t give up easily when seeing only a couple of answers that were indeed correct as you mentioned (I never said it wasn’t) but not necessary providing solutions. So, I searched for other ways and found a solution for the “arithmetic string expression” problem and I was happy to go back to my thread, post the solution and share it with you all.

However, that was a huge effort for the programmer who made the solution and I wanted to insist that there is perhaps a better way to do things and share with the forum.

Thanks for the comments!

Regards,
Cosmo
 
Is it possible to have a stream write new code to a .cpp file and then call the VC++ compiler using COM stuff or something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top