Double pointers

AndyC andy at squeakycode.net
Sat Nov 14 18:41:06 UTC 2026


Hi all.  I'm wondering if there is a way to avoid double pointers 
in something like this:

```D
module ptrptr;

import std.stdio;

struct Rec {
	string name;
	string pin;
	string id;
}

void main() {
	Rec[string] table;
	table["uart"] = Rec(name: "uart", pin: "K54");
	table["clk"] = Rec(name: "clk", pin: "A22");


	Rec*[string] pinIndex;
	foreach(n, ref r; table) {
		pinIndex[r.pin] = &r;
	}

	auto at = "K54" in pinIndex;
	if (at) {
		writeln(**at);
	}
}
```

I have a table of data that I'd like to find elements by name, or 
by pin.  I'd like to be able to update the same element.  But 
when I search by pin, I get this **at double pointer.  It works, 
but feels like there might be a better way.

Thanks,

-Andy


More information about the Digitalmars-d-learn mailing list