unsafe goto gist

monkyyy crazymonkyyy at gmail.com
Tue Apr 15 15:30:27 UTC 2025


its undocumented leaving this code as an example

```d
import std.stdio;
import std.random;
import core.sys.posix.setjmp;

jmp_buf jump;
void main(){
	final switch(setjmp(jump)){//mandated pattern, idk how c knows, 
cant be s implied to 0
		case 0:
			"starting".writeln;
			a(); break;
		case 1:
			"ending".writeln; break;
}}

void a(){
	"a".writeln;
	if(uniform(0,2)){
		b();
	} else {
		c();
	}
	assert(0);
}

void b(){
	"b".writeln;
	if(uniform(0,2)){
		a();
	} else {
		c();
	}
	assert(0);
}
void c(){
	"c".writeln;
	switch(uniform(0,10)){
		case 0:
			"end".writeln;
			longjmp(jump,1); break;
		default:
			if(uniform(0,2)){
					a();
				} else {
					b();
			}
}}
```


More information about the Digitalmars-d mailing list