Created
September 29, 2023 11:37
-
-
Save run-dlang/61093d79096db916f7adfb8ed8c039ce to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std; | |
// Proof of concept. | |
// Out of scope access to a variable using stored pointer, demonstration. | |
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment