Associate information with a pointer address.

BoQsc vaidas.boqsc at gmail.com
Fri Sep 29 11:43:51 UTC 2023


Out of scope access to a variable using stored pointer address, 
demonstration.

```
import std;

void outofcontext()
{
     writeln("Hello D ", associative);
     foreach (pointeraddress, information; associative)
     {
         writeln(*cast(string*)pointeraddress);
     }

}

static string[void* ] associative;

void main()
{
     writeln("Hello D ", associative);

     string variable = "hi";
     void* pointeraddress = &variable;
     associative[pointeraddress] = "someinformation";

     outofcontext();
}
```
https://run.dlang.io/is/QVgL1J
![](https://i.imgur.com/DZqXtj4.png)



More information about the Digitalmars-d-learn mailing list