Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created September 29, 2023 11:37
Show Gist options
  • Save run-dlang/61093d79096db916f7adfb8ed8c039ce to your computer and use it in GitHub Desktop.
Save run-dlang/61093d79096db916f7adfb8ed8c039ce to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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