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 SkipVought 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
0
0
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

 
It is unclear to me then I have two proposal solution for you:

1. Equivalent to your C++ example

string pszVar = “int iVar = 10;”;

2. Using "Emitting Dynamic Assemblies" which allows you to
- Defines assemblies at run time and then runs and/or saves them to disk.
- Defines modules in new assemblies at run time and then runs and/or saves them to disk.
- Defines types at run time, creates instances of these types, and invokes the type's methods.
- Defines symbolic information for defined modules that can be used by tools such as debuggers and code profilers.
See .NET Framework Developer's Guide for more details.

Minh Hoa
 
Thank you Minh Hoa for your answer! I really appreciate and I must apologize my mistake to have posted this question in the C# forum. I meant to post it in the C++ section.

Anyways I liked your idea of defining types at run time. It just could work very well.

Many languages that have this feature of creating code at run-time were developed in C/C++ so then I believe is possible also do it in native C++.

Regards,
Cosmo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top