|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Identifiers in C++
You can't do this with any compiled language that doesn't have a keyword or
accompanying symbol table to accomplish the task. I've never seen anyway to
do this in C++ (although there's the printf(#macro); trick which could be
handy someday) and the reason why is simple - unless your string is chucked
through the pre-processor then there is no way to tell what that string
references since all labels are reduced to addresses at compile time.
The reason javascript can do this is because it's an interpreted language;
all the symbols are there at runtime. From what I understand of Java, it's a
compiled language therefore I'm assuming it loses all symbols in this
process (like most, if not all). So don't assume just because javascript
does it, java must.
A good thing to try would be to get your compiler to output a symbol file
(.SYM file). This will print to file, all your variables and their
addresses. You could then scan the file and build your own internal symbol
table. Say, to assign a variable a value you could do...
AssignVariable("myVar", value);
It's a perfectly legitimate process (although quite ugly). I think Microsoft
has actually automated this process somewhat, they have debugging libraries
which will allow you to reference variables by their string name. It is VERY
Microsoft specific and will only work when you are running a debug build so
that's really not that useful outside of debugging purposes.
Seeya,
- Don
-----Original Message-----
From: Karl Brehme <Karl@1planning.com.br>
To: 'gameprogrammer@gameprogrammer.com' <gameprogrammer@gameprogrammer.com>
Date: 14 September 1999 14:18
Subject: RE: Identifiers in C++
I think not.... not in normal ways... nor function or macro inside VC....
But you can try to construct your own... making indexes inside tables in
memory.... but.... is really complex, I think, considering that the eval
function of javascript, for example, that makes it, is a kind of function
that compiles on the fly the string... that can be watheer command line,
function, variable, from your code or from wathever function of all
APIs......
or.... change do Java... if JavaScript has it... Java maybe has it too...
Karl Heinz Brehme
-----Original Message-----
From: gameprogrammer-owner@gameprogrammer.com
[mailto:gameprogrammer-owner@gameprogrammer.com]On Behalf Of Ash
Stirling
Sent: Terça-feira, 14 de Setembro de 1999 07:58
To: gameprogrammer@gameprogrammer.com
Subject: Identifiers in C++
Hi,
I'm trying to reference a variable by the contents of a variable. That
is,
x = "myVar";
y = myClass.(x);
where the desired result is to have 7 = myClass.myVar . Is this possible
under (MS) Visual C++ 4.0? If I can do this, it will same me a lot of time
and will make my program much more flexible. Thanks in advance.
Ash David Stirling Email: (ashley@roadrunner.nf.net)
Department of Computer Science Phone: (709) 739-0022
Memorial University of Newfoundland
St. John's, Newfoundland, Canada
=================================================================
To SUBSCRIBE or UNSUBSCRIBE please visit
http://gameprogrammer.com/mailinglist.html
======================
To SUBSCRIBE or UNSUBSCRIBE please visit
http://gameprogrammer.com/mailinglist.html
=================================================================
To SUBSCRIBE or UNSUBSCRIBE please visit
http://gameprogrammer.com/mailinglist.html
|
|