Indirect access to variables.
DLearner
bmqazwsx123 at gmail.com
Sat Dec 30 14:26:11 UTC 2023
On Friday, 29 December 2023 at 21:25:44 UTC, user1234 wrote:
>[...]
Thanks, and the ideas are useful,
but please see below, suppose:
```
void main() {
size_t var1 = 1;
size_t var2 = 3;
size_t var3 = 5;
// ... Many other variables defined.
char[4] VarName;
// ...
// And some complicated logic finishes:
VarName = cast(char[4])("var2");
// _Without_ previously storing the addresses of
// all the 'var' variables, how do I get access
// to the variable currently (run-time) named in VarName?
//
// Is there a compiler-provided
// 'introspection' function that would do this?
//
// Labouring the point: If there is an int variable intVar,
// whose name ("intVar") is held in a string variable strVar,
// then there is a compiler function __fnAddrVar() such that
// assert(__fnAddrVar(strVar) == &intVar)
// is true?
}
```
More information about the Digitalmars-d-learn
mailing list