Jim ----------------------------------------
Friends are generally of the same sex, for when men and women agree,it is only in the conclusions; their reasons are always different.
Hm, I'm not happy about this, but I'm not an expert. By rights it ought not to be possible.
Reason: I think you want to get the contents of a string variable at run-time by refering to it by its name (which you have in another variable). But the name is just what you use to tell the compiler what you are referring to, at compile time. The name you use, at least in theory, need not appear anywhere in the compiled product - after all, the processor doesn't refer to variables by name, and the compiled product is for the processor, to use at run time.
Therefore to ensure that the contents of a variable could be got at run-time by name reference, all compilers would have to provide a list of variable names in the compiled exe product, which would encourage very inefficient exe files. It sort-of bypasses the point of using a get-between-the-bytes compiled language like C++, and tends towards the province of an interpreted language.
But maybe I've misunderstood what you want to do.
You can of course write your own variable-tracking system where you retain names of "variables" and associated values, and write your own function that returns the value when it's passed the name. I think that is what doherty is doing.
Please tell me someone if I'm writing total rubbish...
I might be utterly wrong, though, so watch this space! It's amazing how often someone comes back and either (a) tells me how to do the impossible, or (b) says where to find some library that helps to provide what's needed to solve the problem.
No, I think what he/she is trying to do is to make one variable refer to another by name. He has a string variable called VS1, and he has another string holding the text "VS1", and he wants to pass this second string variable to a function that will then identify the first variable by its name ("VS1" and return the contents of the first string variable.
Do let me know, modnm, if I've misunderstood you. I'm guessing this on the basis that others have asked similar questions.
I think this would be asking a bit much of a compiler because normally, at compile time, it will translate all the names of variables into appropriate addressing, and the names themselves then lose all significance, and need not even feature in the final exe file (though for all I know they might do. I've never gone looking. They probably do in files compiled as suitable for debugging). So for instance a global variable called "bloggs" is probably just an offset of, say, 268, in the data segment, so far as the compiled file is concerned. It no longer has the name "bloggs" associated with it at run time.
It is not in the nature of a compiled language to refer to variables by name in strings, though it is very much in the nature of an interpreted script language.
But I'm sure there are plenty of pointer-based ways to achieve the right effect in different ways. After all, the compiler itself is just a program that can quite happily identify variables by their names!
lionelhill Hi
No You did not misunderstood my .
That is exactly what I want to do .
But my question remains. How does the debugger refers to a variable by its name, and if the debugger can to it, why can’t we??.
In order to allow the debugger to refer to variables by name, the compiler has to insert special debug info into the object files. Having that info is the exception rather than the rule.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.