www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - longjmp [still] crashes on windows?

reply tipdbmp <email example.com> writes:
An old thread about the same problem: 
https://forum.dlang.org/thread/mmxwhdypncaeikknlpyq forum.dlang.org

struct jmp_buf {
     byte[256] data;
}

jmp_buf my_jmp_buf;

extern(C) {
     int setjmp(ref jmp_buf env);
     void longjmp(ref jmp_buf env, int);
}

void
second() {
     writefln("second");
     // calling 'longjmp' results in a crash with '-m64'
     // it works with '-m32mscoff'
     longjmp(my_jmp_buf, 1);
}

void
first() {
     second();
     writefln("first");
}

void
main() {
     if (setjmp(my_jmp_buf)) {
         writefln("we longjmp-ed to here");
     }
     else {
         first();
     }
}

I also want to use '-betterC' (exceptions won't work).
Oct 16 2018
parent tipdbmp <email example.com> writes:
SrMordred had already figured it (setjmp vs _setjmp(..., null)) 
out: 
https://forum.dlang.org/post/abrjmdvvlqdmmnpxcdzh forum.dlang.org
Oct 16 2018