Is there a way to convert a string to a function call or other valid C statement? Say I have a string char *some_func_call. Can I use what is in that string to create a valid C statement and execute it?
This is a discussion on Convert a string to a statement? within the C Programming forums, part of the General Programming Boards category; Is there a way to convert a string to a function call or other valid C statement? Say I have ...
Is there a way to convert a string to a function call or other valid C statement? Say I have a string char *some_func_call. Can I use what is in that string to create a valid C statement and execute it?
No, but you can map strings to function pointers.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Pointers to functions article below may help
http://www.cplusplus.com/doc/tutorial/pointers.html
What you are asking to do is typically what can easily be done in an interpreted language, like a Perl or Ruby script. In a compiled language, it is difficult to do unless you've specifically planned for it ahead of time.
Mac and Windows cross platform programmer. Ruby lover.
Quote of the Day
12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.
Amen brother!