Hello,
I want to write a program that will print all the variable names used in that code. Just like "who" in MATLAB prints all the variables used in the program.
Please guide me a bit.
Hello,
I want to write a program that will print all the variable names used in that code. Just like "who" in MATLAB prints all the variables used in the program.
Please guide me a bit.
I'm no expert on this topic, but to the best of my knowledge, when you write C/C++ code the name of the variables are 'superficial', what I mean by that is that the names are used by the compiler as a means to make it easier for the programmer to write/read the code. The computer doesn't see the names of the variables you give, but instead simply sees a series of memory addresses, pointers etc. The reason why you can see the variable names in matlab is because matlab scripts don't interface with the OS but instead run through a virtual machine (similar to how the java virtual machine works).
You could try to set up a structure for a given variable and within the structure you have different attributes, one of these could be the variable name you've specified. I don't really see the point of a program which spits out the names of the variables you've specified unless you go all the way and design your own scriptable language, but maybe that is your intention, I don't know.
Like I said, I'm no expert, but to the best of my knowledge that is how this stuff works. If someone corrects me, then I'll be learning too
Do you know what you want to do?
You can't do anything like that on runtime or in compile time. C++ is not a scripting language!
If you want to get a list of all the variables (all the symbols) you need to compile your progam with debugging options turned on, and then, using appropriate tools/debugger acquire the list of all symbols.
Last edited by kmdv; 09-29-2010 at 09:46 AM.