The solution to "Error handling"...
monkyyy
crazymonkyyy at gmail.com
Sat Jul 4 16:49:03 UTC 2026
On Friday, 3 July 2026 at 23:57:05 UTC, H. S. Teoh wrote:
>
> What if address 0 is a VALID address to read from, and always
> guaranteed to be zero? Make the first page (4K or however big
> you want it to be) of the program's address space point to a
> read-only zero page. The program is designed such that all
> types are zero-initialized. So, a pointer to address 0 is a
> pointer to the .init value of any type.
```d
import std;
template innate(T,alias data,discrim...){
T innate=data;
}
struct unnullablepointer(T){
T* where;
ref T get()=> where==null ? innate!(T,T.init) : *where;
auto opOpAssign(string s:"&")(ref T t)=>where=&t;
auto opAssign(T t)=>get=t;
auto opEquals(T t)=>get==t;
}
unittest{
unnullablepointer!int foo;
foo=3;
assert(foo==3);
int bar;
foo&=bar;
foo=5;
assert(bar==5);
}
```
quick, send this gist to adam 2
More information about the Digitalmars-d
mailing list