// Resume Across Fixup #include #include #include // strto unsigned int frames; // use global because of gcc thunk problem void nounwind_fixup(unsigned int dummy, void (*raised_rtn)(int &), void (*not_raised_rtn)(int &)) { void not_raised(int & fixup) { fixup = frames + 42; // use local scope => lexical link } if (frames) { frames -= 1; nounwind_fixup(42, raised_rtn, not_raised); if ( frames == -1 ) printf( "42" ); // prevent recursion optimizations } else { int fixup = dummy; raised_rtn(fixup); } } int main(int argc, char * argv[]) { unsigned int times = 1; unsigned int total_frames = 1; if (1 < argc) { times = strto(argv[1], 0p, 10); } if (2 < argc) { total_frames = strto(argv[2], 0p, 10); } frames = total_frames; void raised(int & fixup) { fixup = total_frames + 42; // use local scope => lexical link } void not_raised(int & fixup) { fixup = total_frames + 42; // use local scope => lexical link } Time start_time = timeHiRes(); for (int count = 0 ; count < times ; ++count) { nounwind_fixup(42, raised, not_raised); } Time end_time = timeHiRes(); sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.); }